]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Prevent signed overflow in get_time_seed 662/head
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 22 Aug 2020 11:23:23 +0000 (13:23 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sat, 22 Aug 2020 11:25:21 +0000 (13:25 +0200)
Casting time(2) return value to int and multiplying the result with
such a constant will definitely lead to a signed overflow by this day.

Since signed overflows are undefined behaviour in C, avoid this.

Casting to unsigned is more than enough since the upper bits of a
64 bit time_t value will be removed with the int conversion anyway.

random_seed.c

index c428da9c67c6b12f9cf8f49a6d0efb2e6d5f61db..b4c0afd3d443a446e659f83630982b0899c71e4d 100644 (file)
@@ -305,7 +305,7 @@ static int get_time_seed(void)
 {
        DEBUG_SEED("get_time_seed");
 
-       return (int)time(NULL) * 433494437;
+       return (unsigned)time(NULL) * 433494437;
 }
 
 /* json_c_get_random_seed */