From: Alex Rousskov Date: Sun, 23 May 2010 23:04:05 +0000 (-0600) Subject: Fixed IpAddress port printing for ports higher than 9999: X-Git-Tag: SQUID_3_2_0_1~202 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d44d76cf58b74122eed3524cdd8227866b694f5d;p=thirdparty%2Fsquid.git Fixed IpAddress port printing for ports higher than 9999: 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. --- diff --git a/src/ip/Address.cc b/src/ip/Address.cc index 6ed6234842..69e406e236 100644 --- a/src/ip/Address.cc +++ b/src/ip/Address.cc @@ -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