From: Tobias Brunner Date: Tue, 8 Jun 2021 13:33:36 +0000 (+0200) Subject: receiver: Avoid division by 0 after system start if CLOCK_MONOTONIC is used X-Git-Tag: 5.9.3dr4~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a90716cd4d5bd6e580ef3a671ac37378c6c3acca;p=thirdparty%2Fstrongswan.git receiver: Avoid division by 0 after system start if CLOCK_MONOTONIC is used Depending on how CLOCK_MONOTONIC is implemented, time_monotonic() might return 0 within 1 second after the system is started. If that's the case, we just default to 0 for now to avoid a crash (doesn't "hide" the system time, but it's only the uptime anyway in this case). Closes strongswan/strongswan#435. --- diff --git a/src/libcharon/network/receiver.c b/src/libcharon/network/receiver.c index b191ed8d6a..ab520fea61 100644 --- a/src/libcharon/network/receiver.c +++ b/src/libcharon/network/receiver.c @@ -629,7 +629,7 @@ receiver_t *receiver_create() }, .esp_cb_mutex = mutex_create(MUTEX_TYPE_DEFAULT), .secret_switch = now, - .secret_offset = random() % now, + .secret_offset = now ? random() % now : 0, ); if (lib->settings->get_bool(lib->settings,