aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2024-02-20 12:30:34 +0100
committerCorinna Vinschen <corinna@vinschen.de>2024-02-20 12:30:51 +0100
commit12b85bec0e4db176cb5c6534f01bef62fb15c44b (patch)
treee0573bef735f42a083f6a60fed780148802dfae1
parent57b9425878dc796f5dd65970a3ee11fb6d973c45 (diff)
downloadnewlib-12b85bec0e4db176cb5c6534f01bef62fb15c44b.zip
newlib-12b85bec0e4db176cb5c6534f01bef62fb15c44b.tar.gz
newlib-12b85bec0e4db176cb5c6534f01bef62fb15c44b.tar.bz2
Cygwin: gettimeofday: allow tv NULL pointer
Add a missing check for the struct timeval pointer being NULL. Reported-by: 109224573 <109224573@qq.com> Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
-rw-r--r--winsup/cygwin/release/3.5.13
-rw-r--r--winsup/cygwin/times.cc9
2 files changed, 9 insertions, 3 deletions
diff --git a/winsup/cygwin/release/3.5.1 b/winsup/cygwin/release/3.5.1
index 96d2ad3..f3983c4 100644
--- a/winsup/cygwin/release/3.5.1
+++ b/winsup/cygwin/release/3.5.1
@@ -20,3 +20,6 @@ Fixes:
- Fix the problem that VMIN and VTIME does not work at all in console.
- Fix a bug that cannot handle consoles more than 32, rather than 64.
+
+- Fix gettimeofday not checking for a NULL pointer
+ Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255473.html
diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index ddea061..68f7a45 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -172,10 +172,13 @@ gettimeofday (struct timeval *__restrict tv, void *__restrict tzvp)
static bool tzflag;
LONGLONG now = get_clock (CLOCK_REALTIME)->usecs ();
- tv->tv_sec = now / USPERSEC;
- tv->tv_usec = now % USPERSEC;
+ if (tv)
+ {
+ tv->tv_sec = now / USPERSEC;
+ tv->tv_usec = now % USPERSEC;
+ }
- if (tz != NULL)
+ if (tz)
{
if (!tzflag)
{