[newlib-cygwin/main] Cygwin: clock_settime: fail with EINVAL if tv_nsec is negative

Christian Franke chrfranke@sourceware.org
Wed Apr 30 11:30:16 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=38d22e4ba4e95d1be79055267610117f4ee249be

commit 38d22e4ba4e95d1be79055267610117f4ee249be
Author: Christian Franke <christian.franke@t-online.de>
Date:   Mon Apr 28 17:27:28 2025 +0200

    Cygwin: clock_settime: fail with EINVAL if tv_nsec is negative
    
    Addresses: https://sourceware.org/pipermail/cygwin-patches/2025q2/013665.html
    Fixes: 6758d2a3aae6 ("(clock_settime): New function.")
    Signed-off-by: Christian Franke <christian.franke@t-online.de>

Diff:
---
 winsup/cygwin/times.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/times.cc b/winsup/cygwin/times.cc
index a89980d08..3c3ba9236 100644
--- a/winsup/cygwin/times.cc
+++ b/winsup/cygwin/times.cc
@@ -490,7 +490,8 @@ clock_settime (clockid_t clk_id, const struct timespec *tp)
       return -1;
     }
 
-  if (clk_id != CLOCK_REALTIME_COARSE && clk_id != CLOCK_REALTIME)
+  if ((clk_id != CLOCK_REALTIME_COARSE && clk_id != CLOCK_REALTIME)
+      || tp->tv_nsec < 0) /* Otherwise -999...-1 would be accepted */
     {
       set_errno (EINVAL);
       return -1;


More information about the Cygwin-cvs mailing list