From: Daniel Stenberg Date: Thu, 1 Jan 2026 11:45:45 +0000 (+0100) Subject: inet_ntop: avoid the strlen() X-Git-Tag: curl-8_18_0~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7d8725a558a154de032368bd42205bab10d1c4f;p=thirdparty%2Fcurl.git inet_ntop: avoid the strlen() Also, skip adding the terminating null that is not used. Closes #20139 --- diff --git a/lib/curlx/inet_ntop.c b/lib/curlx/inet_ntop.c index 6b4472bab2..6bea5e1db6 100644 --- a/lib/curlx/inet_ntop.c +++ b/lib/curlx/inet_ntop.c @@ -181,10 +181,9 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size) */ if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) *tp++ = ':'; - *tp++ = '\0'; /* Check for overflow, copy, and we are done. */ - if((size_t)(tp - tmp) > size) { + if((size_t)(tp - tmp) >= size) { #ifdef USE_WINSOCK errno = WSAEINVAL; #else @@ -193,7 +192,7 @@ static char *inet_ntop6(const unsigned char *src, char *dst, size_t size) return NULL; } - curlx_strcopy(dst, size, tmp, strlen(tmp)); + curlx_strcopy(dst, size, tmp, tp - tmp); return dst; }