]> 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)
committerLuca Boccassi <luca.boccassi@gmail.com>
Fri, 27 Feb 2026 20:05:57 +0000 (20:05 +0000)
No functional change. Just refactoring and adding assertion.

(cherry picked from commit 7e81423fb880abaef9c9db1e2eecb7039ed7a546)
(cherry picked from commit 842a87e5eb4c71a551d4f62815c8324580f32dbf)
(cherry picked from commit 33e61c0af66bd7a5b9014920c86774f09b78ec44)

src/journal/journald-syslog.c

index c04115ab9f11e3834a797f8f038c9acdc1fdd1d7..3d55f9f5cd8823c43f150fd85bd989a889f96dc8 100644 (file)
@@ -237,7 +237,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,
@@ -257,8 +257,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);
@@ -295,13 +295,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 server_process_syslog_message(