Unless there's a good reason to wait, we ought to validate the input as soon as we have it. There is no reason to wait to validate the input time in this context.
ok? Index: kern_time.c =================================================================== RCS file: /cvs/src/sys/kern/kern_time.c,v retrieving revision 1.159 diff -u -p -r1.159 kern_time.c --- kern_time.c 5 Dec 2022 23:18:37 -0000 1.159 +++ kern_time.c 14 Dec 2022 23:51:14 -0000 @@ -375,19 +375,22 @@ sys_settimeofday(struct proc *p, void *v if ((error = suser(p))) return (error); /* Verify all parameters before changing time. */ - if (tv && (error = copyin(tv, &atv, sizeof(atv)))) - return (error); - if (tzp && (error = copyin(tzp, &atz, sizeof(atz)))) - return (error); - if (tv) { - struct timespec ts; - + if (tv != NULL) { + error = copyin(tv, &atv, sizeof(atv)); + if (error) + return error; #ifdef KTRACE if (KTRPOINT(p, KTR_STRUCT)) ktrabstimeval(p, &atv); #endif if (!timerisvalid(&atv)) return (EINVAL); + } + if (tzp && (error = copyin(tzp, &atz, sizeof(atz)))) + return (error); + if (tv) { + struct timespec ts; + TIMEVAL_TO_TIMESPEC(&atv, &ts); if ((error = settime(&ts)) != 0) return (error);