diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-04-21 20:22:51 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-14 08:09:18 +0100 |
commit | 70a05c1bd337152b69a64c297a883d2790eee14f (patch) | |
tree | e732b3930a2791fcfea01b47b0a37d4a28df3874 | |
parent | b68d68a660f90653f55f3d7361200ab498d2c95b (diff) |
core: make unit deserialization more defensive
-rw-r--r-- | src/shared/time-util.c | 15 | ||||
-rw-r--r-- | src/shared/time-util.h | 2 |
2 files changed, 10 insertions, 7 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c index 1c36c577c..12f1b193b 100644 --- a/src/shared/time-util.c +++ b/src/shared/time-util.c @@ -398,18 +398,21 @@ void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) { t->monotonic); } -void dual_timestamp_deserialize(const char *value, dual_timestamp *t) { +int dual_timestamp_deserialize(const char *value, dual_timestamp *t) { unsigned long long a, b; assert(value); assert(t); - if (sscanf(value, "%llu %llu", &a, &b) != 2) - log_debug("Failed to parse finish timestamp value %s", value); - else { - t->realtime = a; - t->monotonic = b; + if (sscanf(value, "%llu %llu", &a, &b) != 2) { + log_debug("Failed to parse finish timestamp value %s.", value); + return -EINVAL; } + + t->realtime = a; + t->monotonic = b; + + return 0; } int parse_timestamp(const char *t, usec_t *usec) { diff --git a/src/shared/time-util.h b/src/shared/time-util.h index fca8a4db9..7a64d454a 100644 --- a/src/shared/time-util.h +++ b/src/shared/time-util.h @@ -94,7 +94,7 @@ char *format_timestamp_relative(char *buf, size_t l, usec_t t); char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy); void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t); -void dual_timestamp_deserialize(const char *value, dual_timestamp *t); +int dual_timestamp_deserialize(const char *value, dual_timestamp *t); int parse_timestamp(const char *t, usec_t *usec); |