This is an automated email from the ASF dual-hosted git repository. ChristopherSchultz pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat-connectors.git
commit e6e066ed7cf4903bc52ce5d0e73464e7d389b587 Author: Christopher Schultz <[email protected]> AuthorDate: Mon Jun 8 14:33:59 2026 -0400 Respect the return value from inet_ntop4/inet_ntop6 --- native/common/jk_connect.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/native/common/jk_connect.c b/native/common/jk_connect.c index 120bc9551..6b9d85418 100644 --- a/native/common/jk_connect.c +++ b/native/common/jk_connect.c @@ -1320,6 +1320,10 @@ char *jk_dump_sinfo(jk_sock_t sd, char *buf, size_t size) struct sockaddr_storage lsaddr; socklen_t salen; + if (size == 0) { + return buf; + } + salen = sizeof(lsaddr); if (getsockname(sd, (struct sockaddr *)&lsaddr, &salen) == 0) { salen = sizeof(rsaddr); @@ -1330,14 +1334,22 @@ char *jk_dump_sinfo(jk_sock_t sd, char *buf, size_t size) struct sockaddr *rsa = (struct sockaddr *)&rsaddr; if (lsa->sa_family == JK_INET) { struct sockaddr_in *insa = (struct sockaddr_in *)lsa; - inet_ntop4((unsigned char *)&insa->sin_addr, buf, size); - snprintf(pb, sizeof(pb), ":%u", ntohs(insa->sin_port)); + if (inet_ntop4((unsigned char *)&insa->sin_addr, buf, size) == NULL) { + buf[0] = '\0'; + snprintf(pb, sizeof(pb), "InvalidAddr"); + } else { + snprintf(pb, sizeof(pb), ":%u", ntohs(insa->sin_port)); + } } #if JK_HAVE_IPV6 else if (lsa->sa_family == JK_INET6) { struct sockaddr_in6 *insa = (struct sockaddr_in6 *)lsa; - inet_ntop6((unsigned char *)&insa->sin6_addr, buf, size); - snprintf(pb, sizeof(pb), ":%u", ntohs(insa->sin6_port)); + if (inet_ntop6((unsigned char *)&insa->sin6_addr, buf, size) == NULL) { + buf[0] = '\0'; + snprintf(pb, sizeof(pb), "InvalidAddr"); + } else { + snprintf(pb, sizeof(pb), ":%u", ntohs(insa->sin6_port)); + } } #endif else { @@ -1358,14 +1370,22 @@ char *jk_dump_sinfo(jk_sock_t sd, char *buf, size_t size) if (rsa->sa_family == JK_INET) { struct sockaddr_in *insa = (struct sockaddr_in *)rsa; - inet_ntop4((unsigned char *)&insa->sin_addr, buf + ps, size - ps); - snprintf(pb, sizeof(pb), ":%u", ntohs(insa->sin_port)); + if (inet_ntop4((unsigned char *)&insa->sin_addr, buf + ps, size - ps) == NULL) { + buf[ps] = '\0'; + snprintf(pb, sizeof(pb), "InvalidAddr"); + } else { + snprintf(pb, sizeof(pb), ":%u", ntohs(insa->sin_port)); + } } #if JK_HAVE_IPV6 else if (rsa->sa_family == JK_INET6) { struct sockaddr_in6 *insa = (struct sockaddr_in6 *)rsa; - inet_ntop6((unsigned char *)&insa->sin6_addr, buf + ps, size - ps); - snprintf(pb, sizeof(pb), ":%u", ntohs(insa->sin6_port)); + if (inet_ntop6((unsigned char *)&insa->sin6_addr, buf + ps, size - ps) == NULL) { + buf[ps] = '\0'; + snprintf(pb, sizeof(pb), "InvalidAddr"); + } else { + snprintf(pb, sizeof(pb), ":%u", ntohs(insa->sin6_port)); + } } #endif else { --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
