From: Philip Prindeville Date: Wed, 28 Mar 2018 14:25:28 +0000 (-0600) Subject: Avoid possible SEGVs in select() (in unit tests) X-Git-Tag: release-2.1.9-beta^2~130 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8818c86caf1deb15d5075de1f7b951d4c60be602;p=libevent Avoid possible SEGVs in select() (in unit tests) Per the POSIX definition of select(): http://pubs.opengroup.org/onlinepubs/009696699/functions/pselect.html "Upon successful completion, the select() function may modify the object pointed to by the timout argument." If "struct timeval" pointer is a "static const", it could potentially be allocated in a RO text segment. The kernel would then try to copy back the modified value (with the time remaining) into a read-only address and SEGV. Signed-off-by: Philip Prindeville Closes: #614 (cherry picked from commit 33baa4e59fbf9432d77a19c6b2b45402580b79a5) --- diff --git a/evutil_time.c b/evutil_time.c index 00fd5fb4..d658b30e 100644 --- a/evutil_time.c +++ b/evutil_time.c @@ -141,7 +141,10 @@ evutil_usleep_(const struct timeval *tv) sleep(tv->tv_sec); usleep(tv->tv_usec); #else - select(0, NULL, NULL, NULL, tv); + { + struct timeval tv2 = *tv; + select(0, NULL, NULL, NULL, &tv2); + } #endif }