]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: check the length of timestamp field in syslog message
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Jan 2026 04:41:28 +0000 (13:41 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 3 Feb 2026 12:43:17 +0000 (21:43 +0900)
No functional change. Just refactoring and adding assertion.

src/journal/journald-syslog.c

index 7f89373800133f2e35e8beb18a7744bc0eba1db9..8531addf5b908b5a85788631d09b858238ae6318 100644 (file)
@@ -255,7 +255,7 @@ size_t syslog_parse_identifier(const char **buf, char **identifier, char **pid)
         return l;
 }
 
-static int syslog_skip_timestamp(const char **buf) {
+static size_t syslog_skip_timestamp(const char **buf) {
         enum {
                 LETTER,
                 SPACE,
@@ -275,8 +275,8 @@ static int syslog_skip_timestamp(const char **buf) {
                 SPACE
         };
 
-        const char *p, *t;
-        unsigned i;
+        const char *p;
+        size_t i;
 
         assert(buf);
         assert(*buf);
@@ -313,13 +313,15 @@ static int syslog_skip_timestamp(const char **buf) {
                         if (*p != ':')
                                 return 0;
                         break;
-
                 }
         }
 
-        t = *buf;
+        assert(p >= *buf);
+        size_t n = p - *buf;
+        assert(n <= ELEMENTSOF(sequence));
+
         *buf = p;
-        return p - t;
+        return n;
 }
 
 void manager_process_syslog_message(