summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2020-08-08 01:01:27 +0000
committercheloha <cheloha@cvs.openbsd.org>2020-08-08 01:01:27 +0000
commit2c3e9e9fec86cf935a2c9986b92019bbe65e62cc (patch)
treeebf8f14bc75d839a4737b64203e8210ff9f3a323 /sys/kern
parentd3da3fe8450a36ba026150fc04398aa0e5a3d859 (diff)
adjtime(2): simplify input validation for new adjustment
The current input validation for overflow is more complex than it needs to be. We can flatten the conditional hierarchy into a string of checks just one level deep. The result is easier to read.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/kern_time.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index d5d02b0c670..d1e5c53856a 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_time.c,v 1.133 2020/07/15 21:20:08 cheloha Exp $ */
+/* $OpenBSD: kern_time.c,v 1.134 2020/08/08 01:01:26 cheloha Exp $ */
/* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */
/*
@@ -453,18 +453,14 @@ sys_adjtime(struct proc *p, void *v, register_t *retval)
if (!timerisvalid(&atv))
return (EINVAL);
- if (atv.tv_sec >= 0) {
- if (atv.tv_sec > INT64_MAX / 1000000)
- return EINVAL;
- adjustment = atv.tv_sec * 1000000;
- if (atv.tv_usec > INT64_MAX - adjustment)
- return EINVAL;
- adjustment += atv.tv_usec;
- } else {
- if (atv.tv_sec < INT64_MIN / 1000000)
- return EINVAL;
- adjustment = atv.tv_sec * 1000000 + atv.tv_usec;
- }
+ if (atv.tv_sec > INT64_MAX / 1000000)
+ return EINVAL;
+ if (atv.tv_sec < INT64_MIN / 1000000)
+ return EINVAL;
+ adjustment = atv.tv_sec * 1000000;
+ if (adjustment > INT64_MAX - atv.tv_usec)
+ return EINVAL;
+ adjustment += atv.tv_usec;
rw_enter_write(&tc_lock);
}