diff options
author | teor <teor2345@gmail.com> | 2014-10-12 20:50:10 +1100 |
---|---|---|
committer | teor <teor2345@gmail.com> | 2014-10-12 20:50:10 +1100 |
commit | f51418aabcc2af47f61a97f818b013ade6e45208 (patch) | |
tree | 021ee81515e73fd32822a01751ae1f583115d266 /src/common/util.c | |
parent | f94e5f2e5212034cb8b2666716eeaa61e874065b (diff) | |
download | tor-f51418aabcc2af47f61a97f818b013ade6e45208.tar.gz tor-f51418aabcc2af47f61a97f818b013ade6e45208.zip |
Avoid overflow in format_time_interval, create unit tests
Fix an instance of integer overflow in format_time_interval() when
taking the absolute value of the supplied signed interval value.
Fixes bug 13393.
Create unit tests for format_time_interval().
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/common/util.c b/src/common/util.c index f4d293c838..0ea70952a8 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1670,7 +1670,11 @@ format_time_interval(char *out, size_t out_len, long interval) { /* We only report seconds if there's no hours. */ long sec = 0, min = 0, hour = 0, day = 0; - if (interval < 0) + + /* -LONG_MIN is LONG_MAX + 1, which causes signed overflow */ + if (interval < -LONG_MAX) + interval = LONG_MAX; + else if (interval < 0) interval = -interval; if (interval >= 86400) { |