aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorteor <teor2345@gmail.com>2014-10-12 20:50:10 +1100
committerteor <teor2345@gmail.com>2014-10-12 20:50:10 +1100
commitf51418aabcc2af47f61a97f818b013ade6e45208 (patch)
tree021ee81515e73fd32822a01751ae1f583115d266 /src/common
parentf94e5f2e5212034cb8b2666716eeaa61e874065b (diff)
downloadtor-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')
-rw-r--r--src/common/util.c6
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) {