diff options
author | Roger Dingledine <arma@torproject.org> | 2003-09-19 09:30:34 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2003-09-19 09:30:34 +0000 |
commit | e514ac528c11573b16d0003db4a699e669ff4bcb (patch) | |
tree | 742dffb5f95dd73106104ac085e848e73a2b042c /src | |
parent | 078c5ab6171ff37329381ec3b88c9c9c96a7d2e0 (diff) | |
download | tor-e514ac528c11573b16d0003db4a699e669ff4bcb.tar tor-e514ac528c11573b16d0003db4a699e669ff4bcb.tar.gz |
fix a segfault on truncated log lines
svn:r473
Diffstat (limited to 'src')
-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 c4a5e683c..0f75237c6 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -49,14 +49,22 @@ static INLINE void format_msg(char *buf, size_t buf_len, my_gettimeofday(&now); t = (time_t)now.tv_sec; - n = strftime(buf, buf_len, "%b %d %H:%M:%S", localtime(&t)); + n = strftime(buf, buf_len, "%b %d %H:%M:%S", localtime(&t)); n += snprintf(buf+n, buf_len-n, - ".%.3ld [%s] ", - (long)now.tv_usec / 1000, sev_to_string(severity)); - if (funcname) + ".%.3ld [%s] ", + (long)now.tv_usec / 1000, sev_to_string(severity)); + if(n > buf_len) + n = buf_len; /* the *nprintf funcs return how many bytes they + * _would_ print, if the output is truncated */ + if (funcname) { n += snprintf(buf+n, buf_len-n, "%s(): ", funcname); + if(n > buf_len) + n = buf_len; + } n += vsnprintf(buf+n,buf_len-n,format,ap); + if(n > buf_len) + n = buf_len; buf[n]='\n'; buf[n+1]='\0'; } |