diff options
author | Michal Sekletar <msekleta@redhat.com> | 2012-10-25 16:16:17 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2012-10-28 02:14:41 +0200 |
commit | 3dd8ee8fa693597663b0338235becbb0b7a9520c (patch) | |
tree | 31ba5204e0971b59762676080669f4d8bc6ffc5a | |
parent | 7ca7021a9e0c443d40d0af5e9a7e1962d8032229 (diff) |
util: fix possible integer overflows
-rw-r--r-- | src/shared/util.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 2d4a4c1102..e2f8b1fb78 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -148,6 +148,9 @@ usec_t timespec_load(const struct timespec *ts) { ts->tv_nsec == (long) -1) return (usec_t) -1; + if (USEC_PER_SEC > ((UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / (usec_t) ts->tv_sec)) + return (usec_t) -1; + return (usec_t) ts->tv_sec * USEC_PER_SEC + (usec_t) ts->tv_nsec / NSEC_PER_USEC; @@ -175,6 +178,9 @@ usec_t timeval_load(const struct timeval *tv) { tv->tv_usec == (suseconds_t) -1) return (usec_t) -1; + if (USEC_PER_SEC > (UINT64_MAX - tv->tv_usec) / (usec_t) tv->tv_sec) + return (usec_t) -1; + return (usec_t) tv->tv_sec * USEC_PER_SEC + (usec_t) tv->tv_usec; |