From 8943d8966224ca449b50514aca813d2e19c1a2ff Mon Sep 17 00:00:00 2001 From: dds Date: Wed, 4 Jan 2006 00:47:13 +0000 Subject: Replace tv_usec normalization with the return of EINVAL. This addresses two objections to the previous behavior, and unbreaks the alpha tinderbox build. TODO: update the utimes(2) man page. --- sys/kern/vfs_extattr.c | 30 ++++++------------------------ sys/kern/vfs_syscalls.c | 30 ++++++------------------------ 2 files changed, 12 insertions(+), 48 deletions(-) (limited to 'sys') diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c index 8939d18..946b81c 100644 --- a/sys/kern/vfs_extattr.c +++ b/sys/kern/vfs_extattr.c @@ -2713,25 +2713,6 @@ fchown(td, uap) } /* - * Normalize the tv_usec value of t within the allowed range. - */ -static struct timeval -normalize_timeval(const struct timeval *t) -{ - struct timeval n; - - if (t->tv_usec >= 0 && t->tv_usec < 1000000) - return *t; - n.tv_sec = t->tv_sec + t->tv_usec / 1000000; - n.tv_usec = t->tv_usec % 1000000; - if (n.tv_usec < 0) { - n.tv_sec--; - n.tv_usec += 1000000; - } - return n; -} - -/* * Common implementation code for utimes(), lutimes(), and futimes(). */ static int @@ -2740,7 +2721,7 @@ getutimes(usrtvp, tvpseg, tsp) enum uio_seg tvpseg; struct timespec *tsp; { - struct timeval tv[2], tvn; + struct timeval tv[2]; const struct timeval *tvp; int error; @@ -2757,10 +2738,11 @@ getutimes(usrtvp, tvpseg, tsp) tvp = tv; } - tvn = normalize_timeval(&tvp[0]); - TIMEVAL_TO_TIMESPEC(&tvn, &tsp[0]); - tvn = normalize_timeval(&tvp[1]); - TIMEVAL_TO_TIMESPEC(&tvn, &tsp[1]); + if (tvp[0].tv_usec < 0 || tvp[0].tv_usec > 999999 || + tvp[1].tv_usec < 0 || tvp[1].tv_usec > 999999) + return (EINVAL); + TIMEVAL_TO_TIMESPEC(&tvp[0], &tsp[0]); + TIMEVAL_TO_TIMESPEC(&tvp[1], &tsp[1]); } return (0); } diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 8939d18..946b81c 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -2713,25 +2713,6 @@ fchown(td, uap) } /* - * Normalize the tv_usec value of t within the allowed range. - */ -static struct timeval -normalize_timeval(const struct timeval *t) -{ - struct timeval n; - - if (t->tv_usec >= 0 && t->tv_usec < 1000000) - return *t; - n.tv_sec = t->tv_sec + t->tv_usec / 1000000; - n.tv_usec = t->tv_usec % 1000000; - if (n.tv_usec < 0) { - n.tv_sec--; - n.tv_usec += 1000000; - } - return n; -} - -/* * Common implementation code for utimes(), lutimes(), and futimes(). */ static int @@ -2740,7 +2721,7 @@ getutimes(usrtvp, tvpseg, tsp) enum uio_seg tvpseg; struct timespec *tsp; { - struct timeval tv[2], tvn; + struct timeval tv[2]; const struct timeval *tvp; int error; @@ -2757,10 +2738,11 @@ getutimes(usrtvp, tvpseg, tsp) tvp = tv; } - tvn = normalize_timeval(&tvp[0]); - TIMEVAL_TO_TIMESPEC(&tvn, &tsp[0]); - tvn = normalize_timeval(&tvp[1]); - TIMEVAL_TO_TIMESPEC(&tvn, &tsp[1]); + if (tvp[0].tv_usec < 0 || tvp[0].tv_usec > 999999 || + tvp[1].tv_usec < 0 || tvp[1].tv_usec > 999999) + return (EINVAL); + TIMEVAL_TO_TIMESPEC(&tvp[0], &tsp[0]); + TIMEVAL_TO_TIMESPEC(&tvp[1], &tsp[1]); } return (0); } -- cgit v1.1