]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed IpAddress port printing for ports higher than 9999:
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 23 May 2010 23:04:05 +0000 (17:04 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 23 May 2010 23:04:05 +0000 (17:04 -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.

src/ip/Address.cc

index 6ed6234842a7d0f6dce67305f7d8c88f3c1284c1..69e406e23670e2fd04202bdee8b7e5d6d0e21087 100644 (file)
@@ -1061,9 +1061,9 @@ Ip::Address::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