From: Alex Rousskov Date: Sat, 1 May 2010 04:12:07 +0000 (-0600) Subject: Fixed IpAddress port printing for ports higher than 9999: X-Git-Tag: SQUID_3_2_0_1~93^2~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=842fe4ccb857cf933cec6932c3e89e841732f88c;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. 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. --- diff --git a/src/ip/IpAddress.cc b/src/ip/IpAddress.cc index 5e17d84042..464ad2ba40 100644 --- a/src/ip/IpAddress.cc +++ b/src/ip/IpAddress.cc @@ -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