chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(from parent 1:
7ca7021
)
util: fix possible integer overflows
author
Michal Sekletar
<msekleta@redhat.com>
Thu, 25 Oct 2012 14:16:17 +0000
(16:16 +0200)
committer
Zbigniew Jędrzejewski-Szmek
<zbyszek@in.waw.pl>
Sun, 28 Oct 2012 00:14:41 +0000
(
02:14
+0200)
src/shared/util.c
patch
|
blob
|
history
diff --git
a/src/shared/util.c
b/src/shared/util.c
index 2d4a4c1102bd2f082c247f2c38dc27e873321210..e2f8b1fb7812b46fbae18109fdd3f0f38aa0031b 100644
(file)
--- 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;