]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed IpAddress port printing for ports higher than 9999:
authorAlex Rousskov <rousskov@measurement-factory.com>
Sat, 1 May 2010 04:12:07 +0000 (22:12 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sat, 1 May 2010 04:12:07 +0000 (22:12 -0600)
snprintf includes zero-terminator in its size limit, so 7
rather than 6 bytes are needed to snprintf a colon followed
by 5 port digits.

Whether the bug has any runtime effects in the current code,
I do not know, but I did waste a few hours following
misleading debugging output.

src/ip/IpAddress.cc

index 5e17d8404295d9ef304aed01bc68e9ef3766bccb..464ad2ba40c6b7000e9b777bfbc95e24b6a38bbc 100644 (file)
@@ -1041,9 +1041,9 @@ char* IpAddress::ToURL(char* buf, unsigned int blen) const
 
     p += ToHostname(p, blen);
 
-    if (m_SocketAddr.sin6_port > 0 && p < (buf+blen-6) ) {
-        /* 6 is max length of expected ':port' (short int) */
-        snprintf(p, 6,":%d", GetPort() );
+    if (m_SocketAddr.sin6_port > 0 && p <= (buf+blen-7) ) {
+        // ':port' (short int) needs at most 6 bytes plus 1 for 0-terminator
+        snprintf(p, 7, ":%d", GetPort() );
     }
 
     // force a null-terminated string