diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-11-29 20:39:55 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-11-29 20:39:55 +0000 |
commit | b6b07d1d98878cb90aff4cddbcbe860d6b71d285 (patch) | |
tree | c98dc9b8e741b34e5dca4741b4f2cb9733cf9627 | |
parent | 671a2de762e7b151710484cef2973bb6ef42ec66 (diff) | |
download | tor-b6b07d1d98878cb90aff4cddbcbe860d6b71d285.tar tor-b6b07d1d98878cb90aff4cddbcbe860d6b71d285.tar.gz |
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
-rw-r--r-- | src/common/log.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/common/log.c b/src/common/log.c index 82211c98c..06d333b41 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; } |