]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: add assert for max_size overflow safety
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 20:59:35 +0000 (20:59 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 30 Mar 2026 08:37:31 +0000 (09:37 +0100)
Coverity flags max_size*2 as a potential overflow. The value is
bounded by MAX_SIZE_UPPER (128 MiB) or JOURNAL_COMPACT_SIZE_MAX
(4 GiB), so doubling is safe within uint64_t. Add an assert to
document this.

CID#1548019

Follow-up for 8580d1f73db36e9383e674e388b4fb55828c0c66

src/libsystemd/sd-journal/journal-file.c

index de5d7075e0ccabb9cc57163da20dcd62484d5674..b4efcc050eaaeb928b280690d6423ff7e64f57d1 100644 (file)
@@ -4058,6 +4058,8 @@ static void journal_default_metrics(JournalMetrics *m, int fd, bool compact) {
                 if (m->max_size < JOURNAL_FILE_SIZE_MIN)
                         m->max_size = JOURNAL_FILE_SIZE_MIN;
 
+                /* Silence static analyzers */
+                assert(m->max_size <= UINT64_MAX / 2);
                 if (m->max_use != 0 && m->max_size*2 > m->max_use)
                         m->max_use = m->max_size*2;
         }