Module Name:    src
Committed By:   kre
Date:           Thu Oct 10 11:14:28 UTC 2024

Modified Files:
        src/share/man/man9: ts2timo.9
        src/sys/kern: subr_time.c

Log Message:
PR kern/58733 - avoid ts2timo() clobbering its arg

See the PR for the gory details - in the TIMER_ABSTIME case
ts2timo() should not (really *must* not) alter the timespec
it is passed (in that case it should be const - but for now
anyway, cannot be for the TIMER_RELTIME case, and there is
just one of them!)

XXX pullup -10
XXX pullup -9 (will need a patch).


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/share/man/man9/ts2timo.9
cvs rdiff -u -r1.38 -r1.39 src/sys/kern/subr_time.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man9/ts2timo.9
diff -u src/share/man/man9/ts2timo.9:1.4 src/share/man/man9/ts2timo.9:1.5
--- src/share/man/man9/ts2timo.9:1.4	Wed Oct  9 11:11:54 2024
+++ src/share/man/man9/ts2timo.9	Thu Oct 10 11:14:28 2024
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ts2timo.9,v 1.4 2024/10/09 11:11:54 kre Exp $
+.\"	$NetBSD: ts2timo.9,v 1.5 2024/10/10 11:14:28 kre Exp $
 .\"
 .\" Copyright (c) 2013 Christos Zoulas
 .\" All rights reserved.
@@ -51,7 +51,7 @@ or
 .Dv TIMER_RELTIME .
 If the interval is specified as an absolute time, then the
 .Fa clock_id
-clock is used to convert it to a relative time.
+clock is used to calculate the corresponding relative time.
 If the
 .Fa start
 argument is not
@@ -63,18 +63,23 @@ clock is placed in that argument.
 On success
 .Fn ts2timo
 returns
-.Dv 0 .
+.Dv 0 ,
+and places the computed number of ticks
+in the integer referenced by
+.Fa timo .
 On failure it returns
 .Er ETIMEDOUT
 if  interval computed was
 .Dv 0
-or negative, and
+or negative, or
 .Er EINVAL
-if
+if the
 .Fa ts->tv_nsec
-field in the computed interval is out of range, or the
+field is out of range, or the
 .Fa clock_id
-argument is invalid.
+argument is invalid, or if
+computing the relative time from a supplied absolute value
+would cause an arithmetic overflow.
 .Sh SEE ALSO
 .Xr clock_gettime 2 ,
 .Xr clock_nanosleep 2

Index: src/sys/kern/subr_time.c
diff -u src/sys/kern/subr_time.c:1.38 src/sys/kern/subr_time.c:1.39
--- src/sys/kern/subr_time.c:1.38	Sat Jul  8 20:02:10 2023
+++ src/sys/kern/subr_time.c	Thu Oct 10 11:14:28 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_time.c,v 1.38 2023/07/08 20:02:10 riastradh Exp $	*/
+/*	$NetBSD: subr_time.c,v 1.39 2024/10/10 11:14:28 kre Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.38 2023/07/08 20:02:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_time.c,v 1.39 2024/10/10 11:14:28 kre Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -331,7 +331,8 @@ ts2timo(clockid_t clock_id, int flags, s
 	if ((flags & TIMER_ABSTIME) != 0) {
 		if (!timespecsubok(ts, &tsd))
 			return EINVAL;
-		timespecsub(ts, &tsd, ts);
+		timespecsub(ts, &tsd, &tsd);
+		ts = &tsd;
 	}
 
 	error = itimespecfix(ts);

Reply via email to