summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2018-05-22 18:33:42 +0000
committercheloha <cheloha@cvs.openbsd.org>2018-05-22 18:33:42 +0000
commitedaa4fc85aa6a6f2a7a6371f2282ab83c49cec3c (patch)
tree50a6362302870ab54204c91758f8457f693f1546 /sys/kern
parent0b4fa9bb3d4d2bbaafe1414f86abd2d5043a197b (diff)
nanosleep: ensure tv_nsec input is on [0, 1000000000)
Instead of converting timespec -> timeval and truncating the input, check with timespecfix and use tstohz(9) for the tsleep. All other contemporary systems check this correctly. Also add a regression test for this case. ok tb@
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_time.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index ab86d059e79..8d6a8333f38 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.101 2018/02/19 08:59:52 mpi Exp $ */
+/* $OpenBSD: kern_time.c,v 1.102 2018/05/22 18:33:41 cheloha Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -268,7 +268,6 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval)
struct timespec rqt, rmt;
struct timespec sts, ets;
struct timespec *rmtp;
- struct timeval tv;
int error, error1;
rmtp = SCARG(uap, rmtp);
@@ -283,15 +282,14 @@ sys_nanosleep(struct proc *p, void *v, register_t *retval)
}
#endif
- TIMESPEC_TO_TIMEVAL(&tv, &rqt);
- if (itimerfix(&tv))
+ if (rqt.tv_sec > 100000000 || timespecfix(&rqt))
return (EINVAL);
if (rmtp)
getnanouptime(&sts);
error = tsleep(&nanowait, PWAIT | PCATCH, "nanosleep",
- MAX(1, tvtohz(&tv)));
+ MAX(1, tstohz(&rqt)));
if (error == ERESTART)
error = EINTR;
if (error == EWOULDBLOCK)