[systemd-commits] src/shared

Dave Reisner dreisner at kemper.freedesktop.org
Mon Oct 29 12:54:37 PDT 2012


 src/shared/util.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit 49371bb50e0fe6e9e90309a20006bcfd9e2fa8f4
Author: Dave Reisner <dreisner at archlinux.org>
Date:   Mon Oct 29 15:49:34 2012 -0400

    util: avoid divide by zero FPE
    
    In early userspace, if kernel initialization happens extremely quickly,
    a call to systemd-timestamp can potentially result in division by zero.
    Ensure that the check in timespec_load, which only makes sense if tv_sec
    is greater than zero, is guarded by this condition.

diff --git a/src/shared/util.c b/src/shared/util.c
index e2f8b1f..9a45e60 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -148,7 +148,8 @@ 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))
+        if (ts->tv_sec > 0 &&
+            USEC_PER_SEC > ((UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / (usec_t) ts->tv_sec))
                 return (usec_t) -1;
 
         return



More information about the systemd-commits mailing list