summaryrefslogtreecommitdiff
path: root/include/asterisk/time.h
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2012-04-27 19:30:59 +0000
committerMatthew Jordan <mjordan@digium.com>2012-04-27 19:30:59 +0000
commit50c959580c61a5049e2c6d62436b9414b254bd9f (patch)
treeb7d5956191a3a0e056d9f1ae0cd71a5ac3cdb2e5 /include/asterisk/time.h
parent83cf78deda23b3799751c6a25df83eecf973e348 (diff)
Prevent overflow in calculation in ast_tvdiff_ms on 32-bit machines
The method ast_tvdiff_ms attempts to calculate the difference, in milliseconds, between two timeval structs, and return the difference in a 64-bit integer. Unfortunately, it assumes that the long tv_sec/tv_usec members in the timeval struct are large enough to hold the calculated values before it returns. On 64-bit machines, this might be the case, as a long may be 64-bits. On 32-bit machines, however, a long may be less (32-bits), in which case, the calculation can overflow. This overflow caused significant problems in MixMonitor, which uses the method to determine if an audio factory, which has not presented audio to an audiohook, is merely late in providing said audio or will never provide audio. In an overflow situation, the audiohook would incorrectly determine that an audio factory that will never provide audio is merely late instead. This led to situations where a MixMonitor never recorded any audio. Note that this happened most frequently when that MixMonitor was started by the ConfBridge application itself, or when the MixMonitor was attached to a Local channel. (issue ASTERISK-19497) Reported by: Ben Klang Tested by: Ben Klang Patches: 32-bit-time-overflow-10-2012-04-26.diff (license #6283) by mjordan (closes issue ASTERISK-19727) Reported by: Mark Murawski Tested by: Michael L. Young Patches: 32-bit-time-overflow-2012-04-27.diff (license #6283) by mjordan) (closes issue ASTERISK-19471) Reported by: feyfre Tested by: feyfre (issue ASTERISK-19426) Reported by: Johan Wilfer Review: https://reviewboard.asterisk.org/r/1889/ ........ Merged revisions 364277 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 364285 from http://svn.asterisk.org/svn/asterisk/branches/10 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@364287 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/time.h')
-rw-r--r--include/asterisk/time.h5
1 files changed, 3 insertions, 2 deletions
diff --git a/include/asterisk/time.h b/include/asterisk/time.h
index c78ff2db0..4fa08723b 100644
--- a/include/asterisk/time.h
+++ b/include/asterisk/time.h
@@ -83,8 +83,9 @@ int64_t ast_tvdiff_ms(struct timeval end, struct timeval start),
is handled for positive and negative numbers, by ensuring
that the divisor is always positive
*/
- return ((end.tv_sec - start.tv_sec) * 1000) +
- (((1000000 + end.tv_usec - start.tv_usec) / 1000) - 1000);
+ int64_t sec_dif = (int64_t)(end.tv_sec - start.tv_sec) * 1000;
+ int64_t usec_dif = (1000000 + end.tv_usec - start.tv_usec) / 1000 - 1000;
+ return sec_dif + usec_dif;
}
)