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

Christian Franke via Cygwin-cvs <[email protected]>
Newsgroups gmane.os.cygwin.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=38d22e4ba4e95d1be79055267610117f4ee249be

commit 38d22e4ba4e95d1be79055267610117f4ee249be
Author: Christian Franke <[email protected]>
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 <[email protected]>

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;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.