From: Nick Mathewson Date: Mon, 29 Nov 2004 20:39:55 +0000 (+0000) Subject: Remove needless -2 in log code. This was not an underflow risk, sinze we only call... X-Git-Tag: debian-version-0.0.8+0.0.9rc3-1~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b6b07d1d98878cb90aff4cddbcbe860d6b71d285;p=thirdparty%2Ftor.git Remove needless -2 in log code. This was not an underflow risk, sinze we only call format_msg from one place, where buf_len==10024 svn:r3017 --- diff --git a/src/common/log.c b/src/common/log.c index 82211c98c9..06d333b41a 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -139,10 +139,18 @@ static INLINE char *format_msg(char *buf, size_t buf_len, r = tor_vsnprintf(buf+n,buf_len-n,format,ap); if (r < 0) { - n = buf_len-2; /* XXX is this line redundant with the -=2 above, - and also a source of underflow danger? */ - strlcpy(buf+buf_len-TRUNCATED_STR_LEN-1, TRUNCATED_STR, - buf_len-(buf_len-TRUNCATED_STR_LEN-1)); + /* The message was too long; overwrite the end of the buffer with + * "[...truncated]" */ + if (buf_len >= TRUNCATED_STR_LEN) { + /* This is safe, since we have an extra character after buf_len + to hold the \0. */ + strlcpy(buf+buf_len-TRUNCATED_STR_LEN, TRUNCATED_STR, + buf_len-(buf_len-TRUNCATED_STR_LEN-1)); + } + /* Set 'n' to the end of the buffer, where we'll be writing \n\0. + * Since we already subtracted 2 from buf_len, this is safe.*/ + n = buf_len; + } else { n += r; }