chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tree-wide: make bus_map_all_properties return a proper sd_bus_error
[elogind.git]
/
src
/
basic
/
time-util.c
diff --git
a/src/basic/time-util.c
b/src/basic/time-util.c
index 2333f6a66cefe11e8218a910051135527d9a704b..a2b57f872716a37ecdb6de7adbbaf5f998c431cb 100644
(file)
--- a/
src/basic/time-util.c
+++ b/
src/basic/time-util.c
@@
-217,7
+217,8
@@
nsec_t timespec_load_nsec(const struct timespec *ts) {
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
assert(ts);
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
assert(ts);
- if (u == USEC_INFINITY) {
+ if (u == USEC_INFINITY ||
+ u / USEC_PER_SEC >= TIME_T_MAX) {
ts->tv_sec = (time_t) -1;
ts->tv_nsec = (long) -1;
return ts;
ts->tv_sec = (time_t) -1;
ts->tv_nsec = (long) -1;
return ts;
@@
-246,7
+247,8
@@
usec_t timeval_load(const struct timeval *tv) {
struct timeval *timeval_store(struct timeval *tv, usec_t u) {
assert(tv);
struct timeval *timeval_store(struct timeval *tv, usec_t u) {
assert(tv);
- if (u == USEC_INFINITY) {
+ if (u == USEC_INFINITY||
+ u / USEC_PER_SEC > TIME_T_MAX) {
tv->tv_sec = (time_t) -1;
tv->tv_usec = (suseconds_t) -1;
} else {
tv->tv_sec = (time_t) -1;
tv->tv_usec = (suseconds_t) -1;
} else {
@@
-293,9
+295,11
@@
static char *format_timestamp_internal(
if (t <= 0 || t == USEC_INFINITY)
return NULL; /* Timestamp is unset */
if (t <= 0 || t == USEC_INFINITY)
return NULL; /* Timestamp is unset */
+ /* Let's not format times with years > 9999 */
+ if (t > USEC_TIMESTAMP_FORMATTABLE_MAX)
+ return NULL;
+
sec = (time_t) (t / USEC_PER_SEC); /* Round down */
sec = (time_t) (t / USEC_PER_SEC); /* Round down */
- if ((usec_t) sec != (t / USEC_PER_SEC))
- return NULL; /* overflow? */
if (!localtime_or_gmtime_r(&sec, &tm, utc))
return NULL;
if (!localtime_or_gmtime_r(&sec, &tm, utc))
return NULL;
@@
-561,12
+565,12
@@
void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
}
int dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
}
int dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
- u
nsigned long long
a, b;
+ u
int64_t
a, b;
assert(value);
assert(t);
assert(value);
assert(t);
- if (sscanf(value, "%
llu %llu"
, &a, &b) != 2) {
+ if (sscanf(value, "%
" PRIu64 "%" PRIu64
, &a, &b) != 2) {
log_debug("Failed to parse dual timestamp value \"%s\": %m", value);
return -EINVAL;
}
log_debug("Failed to parse dual timestamp value \"%s\": %m", value);
return -EINVAL;
}
@@
-849,9
+853,16
@@
from_tm:
return -EINVAL;
ret = (usec_t) x * USEC_PER_SEC + x_usec;
return -EINVAL;
ret = (usec_t) x * USEC_PER_SEC + x_usec;
+ if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX)
+ return -EINVAL;
finish:
finish:
+ if (ret + plus < ret) /* overflow? */
+ return -EINVAL;
ret += plus;
ret += plus;
+ if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX)
+ return -EINVAL;
+
if (ret > minus)
ret -= minus;
else
if (ret > minus)
ret -= minus;
else