mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 19:21:53 +03:00
time-util: check for overflow in conversion from ts to nsec_t
CID #1320855.
This commit is contained in:
parent
56e3d0cf5d
commit
a2daa2f075
@ -139,8 +139,7 @@ dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, us
|
|||||||
usec_t timespec_load(const struct timespec *ts) {
|
usec_t timespec_load(const struct timespec *ts) {
|
||||||
assert(ts);
|
assert(ts);
|
||||||
|
|
||||||
if (ts->tv_sec == (time_t) -1 &&
|
if (ts->tv_sec == (time_t) -1 && ts->tv_nsec == (long) -1)
|
||||||
ts->tv_nsec == (long) -1)
|
|
||||||
return USEC_INFINITY;
|
return USEC_INFINITY;
|
||||||
|
|
||||||
if ((usec_t) ts->tv_sec > (UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / USEC_PER_SEC)
|
if ((usec_t) ts->tv_sec > (UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / USEC_PER_SEC)
|
||||||
@ -154,13 +153,13 @@ usec_t timespec_load(const struct timespec *ts) {
|
|||||||
static nsec_t timespec_load_nsec(const struct timespec *ts) {
|
static nsec_t timespec_load_nsec(const struct timespec *ts) {
|
||||||
assert(ts);
|
assert(ts);
|
||||||
|
|
||||||
if (ts->tv_sec == (time_t) -1 &&
|
if (ts->tv_sec == (time_t) -1 && ts->tv_nsec == (long) -1)
|
||||||
ts->tv_nsec == (long) -1)
|
|
||||||
return NSEC_INFINITY;
|
return NSEC_INFINITY;
|
||||||
|
|
||||||
return
|
if ((nsec_t) ts->tv_sec >= (UINT64_MAX - ts->tv_nsec) / NSEC_PER_SEC)
|
||||||
(nsec_t) ts->tv_sec * NSEC_PER_SEC +
|
return NSEC_INFINITY;
|
||||||
(nsec_t) ts->tv_nsec;
|
|
||||||
|
return (nsec_t) ts->tv_sec * NSEC_PER_SEC + (nsec_t) ts->tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
|
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
|
||||||
|
Loading…
Reference in New Issue
Block a user