From: Zbigniew Jędrzejewski-Szmek Date: Thu, 17 May 2018 07:07:58 +0000 (+0200) Subject: journal-remote: verify realtime and monotonic timestamps early X-Git-Tag: v239~172^2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=41b0b1274d34db1605fb78c1c82e420d7e742f6e;p=thirdparty%2Fsystemd.git journal-remote: verify realtime and monotonic timestamps early We would accept any value, and then journal_file_check_object() would reject the whole entry. Let's just ignore the field. --- diff --git a/src/basic/journal-importer.c b/src/basic/journal-importer.c index 7445a308a48..0c7716717f5 100644 --- a/src/basic/journal-importer.c +++ b/src/basic/journal-importer.c @@ -11,6 +11,7 @@ #include "alloc-util.h" #include "fd-util.h" #include "io-util.h" +#include "journal-file.h" #include "journal-importer.h" #include "parse-util.h" #include "string-util.h" @@ -257,31 +258,39 @@ static int process_dunder(JournalImporter *imp, char *line, size_t n) { timestamp = startswith(line, "__REALTIME_TIMESTAMP="); if (timestamp) { - long long unsigned x; + uint64_t x; line[n-1] = '\0'; - r = safe_atollu(timestamp, &x); + r = safe_atou64(timestamp, &x); if (r < 0) - log_warning("Failed to parse __REALTIME_TIMESTAMP: '%s'", timestamp); - else - imp->ts.realtime = x; - return r < 0 ? r : 1; + return log_warning_errno(r, "Failed to parse __REALTIME_TIMESTAMP '%s': %m", timestamp); + else if (!VALID_REALTIME(x)) { + log_warning("__REALTIME_TIMESTAMP out of range, ignoring: %"PRIu64, x); + return -ERANGE; + } + + imp->ts.realtime = x; + return 1; } timestamp = startswith(line, "__MONOTONIC_TIMESTAMP="); if (timestamp) { - long long unsigned x; + uint64_t x; line[n-1] = '\0'; - r = safe_atollu(timestamp, &x); + r = safe_atou64(timestamp, &x); if (r < 0) - log_warning("Failed to parse __MONOTONIC_TIMESTAMP: '%s'", timestamp); - else - imp->ts.monotonic = x; - return r < 0 ? r : 1; + return log_warning_errno(r, "Failed to parse __MONOTONIC_TIMESTAMP '%s': %m", timestamp); + else if (!VALID_MONOTONIC(x)) { + log_warning("__MONOTONIC_TIMESTAMP out of range, ignoring: %"PRIu64, x); + return -ERANGE; + } + + imp->ts.monotonic = x; + return 1; } timestamp = startswith(line, "__"); if (timestamp) { - log_notice("Unknown dunder line %s", line); + log_notice("Unknown dunder line %s, ignoring.", line); return 1; }