summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-22 21:35:53 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-22 21:38:49 +0100
commit86e7b6e3f61e2a0d2395d7f2cc28e8f9199710e7 (patch)
tree0109bbff34c4f57f203ae2b74b790dfa52fa189a
parentbfa00bc6c05d0f896e9632eccd47d442fea556b9 (diff)
timedated: extra overflow safety check when doing relative time changes
Ensure clients don't overflow usec_t when doing relative time changes. This is mostly just paranoia and protection against accidents, after all clients are already authenticated, and they can se the time to any value they wish anyway, but better be safe than sorry. https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1152187/comments/14
-rw-r--r--src/timedate/timedated.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 85506f4fc6..16fffd0844 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -816,15 +816,24 @@ static DBusHandlerResult timedate_message_handler(
struct timespec ts;
struct tm* tm;
+ if (relative) {
+ usec_t n, x;
+
+ n = now(CLOCK_REALTIME);
+ x = n + utc;
+
+ if ((utc > 0 && x < n) ||
+ (utc < 0 && x > n))
+ return bus_send_error_reply(connection, message, NULL, -EOVERFLOW);
+
+ timespec_store(&ts, x);
+ } else
+ timespec_store(&ts, (usec_t) utc);
+
r = verify_polkit(connection, message, "org.freedesktop.timedate1.set-time", interactive, NULL, &error);
if (r < 0)
return bus_send_error_reply(connection, message, &error, r);
- if (relative)
- timespec_store(&ts, now(CLOCK_REALTIME) + utc);
- else
- timespec_store(&ts, utc);
-
/* Set system clock */
if (clock_settime(CLOCK_REALTIME, &ts) < 0) {
log_error("Failed to set local time: %m");