From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id BC2993858D20; Tue, 20 Feb 2024 11:33:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC2993858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1708428794; bh=EeVX2iCYlr/HDCpisV++UvQxyXuizRLjNJ7+ryzdHgw=; h=From:To:Subject:Date:From; b=UakdhvxrhdpAuVU+y5l5XtiYGPb7PeFpl8jPktiFOiFLPYHR4Tdo9z4cbNbst87rI Mb81E94i6CfNuf8sJydgFdzCqc0CE1lspE8L2GwXZHGRJG/MaKQqAf9xzl9mfn7TYS mIFYmb7sEG9/qCTaOSAdYtKWT7XOKS6if+u6+7a0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: gettimeofday: allow tv NULL pointer X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: a7bf7c7dd524ab724913da0019f8b4a5425b5927 X-Git-Newrev: 70653fd8f1db70b8776d22517fa737338eea18c7 Message-Id: <20240220113314.BC2993858D20@sourceware.org> Date: Tue, 20 Feb 2024 11:33:14 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D70653fd8f1d= b70b8776d22517fa737338eea18c7 commit 70653fd8f1db70b8776d22517fa737338eea18c7 Author: Corinna Vinschen AuthorDate: Tue Feb 20 12:30:34 2024 +0100 Commit: Corinna Vinschen CommitDate: Tue Feb 20 12:30:34 2024 +0100 Cygwin: gettimeofday: allow tv NULL pointer =20 Add a missing check for the struct timeval pointer being NULL. =20 Reported-by: 109224573 <109224573@qq.com> Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/release/3.5.1 | 3 +++ winsup/cygwin/times.cc | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/winsup/cygwin/release/3.5.1 b/winsup/cygwin/release/3.5.1 index 96d2ad32fa79..f3983c450dd9 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. =20 - 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 87773934bfd7..71a7210318fa 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 =3D get_clock (CLOCK_REALTIME)->usecs (); =20 - tv->tv_sec =3D now / USPERSEC; - tv->tv_usec =3D now % USPERSEC; + if (tv) + { + tv->tv_sec =3D now / USPERSEC; + tv->tv_usec =3D now % USPERSEC; + } =20 - if (tz !=3D NULL) + if (tz) { if (!tzflag) {