]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-dhcp6-client: fix overflow in calculating timeout value
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 6 Feb 2022 14:25:07 +0000 (23:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 14 Feb 2022 05:43:45 +0000 (14:43 +0900)
src/libsystemd-network/sd-dhcp6-client.c

index ff7e04bbdc6670bc1a873f60fc1c2b05f6009bf1..a830b44f76d7f43d2d9a2cae2509a2e030a7041f 100644 (file)
@@ -808,6 +808,10 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
         return 0;
 }
 
+static usec_t client_timeout_compute_random(usec_t val) {
+        return usec_sub_unsigned(val, random_u64_range(val / 10));
+}
+
 static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata) {
         sd_dhcp6_client *client = userdata;
 
@@ -861,10 +865,6 @@ static int client_timeout_resend_expire(sd_event_source *s, uint64_t usec, void
         return 0;
 }
 
-static usec_t client_timeout_compute_random(usec_t val) {
-        return val - (random_u32() % USEC_PER_SEC) * val / 10 / USEC_PER_SEC;
-}
-
 static int client_timeout_resend(sd_event_source *s, uint64_t usec, void *userdata) {
         int r = 0;
         sd_dhcp6_client *client = userdata;