aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-11-22 12:14:11 -0500
committerNick Mathewson <nickm@torproject.org>2013-11-22 12:14:11 -0500
commit6cbd17470d383616c3b34310ad5716a7c8c8990a (patch)
treef773891f2033ba2f5a29afb58b98e3bfcc4dc8a0
parent027f4c82ebcbe4555e66948f3ee14950661bc11a (diff)
downloadtor-6cbd17470d383616c3b34310ad5716a7c8c8990a.tar
tor-6cbd17470d383616c3b34310ad5716a7c8c8990a.tar.gz
Handle unlikely negative time in tor_log_err_sigsafe
Coverity wants this; CID 1130990.
-rw-r--r--src/common/log.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/common/log.c b/src/common/log.c
index dffda45c5..9c67de320 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -474,7 +474,7 @@ tor_log_err_sigsafe(const char *m, ...)
{
va_list ap;
const char *x;
- char timebuf[32];
+ char timebuf[33];
time_t now = time(NULL);
if (!m)
@@ -483,8 +483,10 @@ tor_log_err_sigsafe(const char *m, ...)
int g = log_time_granularity / 1000;
now -= now % g;
}
- timebuf[0] = '\0';
- format_dec_number_sigsafe(now, timebuf, sizeof(timebuf));
+ timebuf[0] = now < 0 ? '-' : ' ';
+ if (now < 0) now = -now;
+ timebuf[1] = '\0';
+ format_dec_number_sigsafe(now, timebuf+1, sizeof(timebuf)-1);
tor_log_err_sigsafe_write("\n=========================================="
"================== T=");
tor_log_err_sigsafe_write(timebuf);