Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107415413
D30233.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D30233.diff
View Options
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -72,6 +72,8 @@
#define MAKE_PROCESS_CPUCLOCK(pid) \
(CPUCLOCK_BIT|CPUCLOCK_PROCESS_BIT|(pid))
+#define NS_PER_SEC 1000000000
+
static struct kclock posix_clocks[MAX_CLOCKS];
static uma_zone_t itimer_zone = NULL;
@@ -408,8 +410,7 @@
return (error);
if (clock_id != CLOCK_REALTIME)
return (EINVAL);
- if (ats->tv_nsec < 0 || ats->tv_nsec >= 1000000000 ||
- ats->tv_sec < 0)
+ if (ats->tv_nsec < 0 || ats->tv_nsec >= NS_PER_SEC || ats->tv_sec < 0)
return (EINVAL);
if (!allow_insane_settime &&
(ats->tv_sec > 8000ULL * 365 * 24 * 60 * 60 ||
@@ -462,12 +463,12 @@
* Rounding up is especially important if rounding down
* would give 0. Perfect rounding is unimportant.
*/
- ts->tv_nsec = 1000000000 / tc_getfrequency() + 1;
+ ts->tv_nsec = NS_PER_SEC / tc_getfrequency() + 1;
break;
case CLOCK_VIRTUAL:
case CLOCK_PROF:
/* Accurately round up here because we can do so cheaply. */
- ts->tv_nsec = howmany(1000000000, hz);
+ ts->tv_nsec = howmany(NS_PER_SEC, hz);
break;
case CLOCK_SECOND:
ts->tv_sec = 1;
@@ -509,7 +510,7 @@
int error;
bool is_abs_real;
- if (rqt->tv_nsec < 0 || rqt->tv_nsec >= 1000000000)
+ if (rqt->tv_nsec < 0 || rqt->tv_nsec >= NS_PER_SEC)
return (EINVAL);
if ((flags & ~TIMER_ABSTIME) != 0)
return (EINVAL);
@@ -1650,7 +1651,9 @@
itimespecfix(struct timespec *ts)
{
- if (ts->tv_sec < 0 || ts->tv_nsec < 0 || ts->tv_nsec >= 1000000000)
+ if (ts->tv_sec < 0 || ts->tv_nsec < 0 || ts->tv_nsec >= NS_PER_SEC)
+ return (EINVAL);
+ if ((UINT64_MAX - ts->tv_nsec) / NS_PER_SEC < ts->tv_sec)
return (EINVAL);
if (ts->tv_sec == 0 && ts->tv_nsec != 0 && ts->tv_nsec < tick * 1000)
ts->tv_nsec = tick * 1000;
@@ -1658,10 +1661,10 @@
}
#define timespectons(tsp) \
- ((uint64_t)(tsp)->tv_sec * 1000000000 + (tsp)->tv_nsec)
+ ((uint64_t)(tsp)->tv_sec * NS_PER_SEC + (tsp)->tv_nsec)
#define timespecfromns(ns) (struct timespec){ \
- .tv_sec = (ns) / 1000000000, \
- .tv_nsec = (ns) % 1000000000 \
+ .tv_sec = (ns) / NS_PER_SEC, \
+ .tv_nsec = (ns) % NS_PER_SEC \
}
static void
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Jan 14, 8:15 PM (7 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15800597
Default Alt Text
D30233.diff (2 KB)
Attached To
Mode
D30233: posix timers: Check for overflow when converting to ns
Attached
Detach File
Event Timeline
Log In to Comment