]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journald: add assert for allocated buffer size 41413/head
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 22:46:35 +0000 (22:46 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 30 Mar 2026 12:11:25 +0000 (13:11 +0100)
Coverity flags allocated - 1 as a potential underflow when
allocated is 0. After GREEDY_REALLOC succeeds the buffer is
guaranteed non-empty, but Coverity cannot trace through the
conditional. Add an assert to document this.

CID#1548053

Follow-up for ec20fe5ffb8a00469bab209fff6c069bb93c6db2

src/journal/journald-stream.c

index 677fb93b7597f538b311eec752187813d4ca6772..ee903755cf7a4d970414ab408bb854dc421a6224 100644 (file)
@@ -557,6 +557,8 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents,
 
         /* Try to make use of the allocated buffer in full, but never read more than the configured line size. Also,
          * always leave room for a terminating NUL we might need to add. */
+        /* Silence static analyzers, GREEDY_REALLOC above ensures allocated > 0 */
+        assert(allocated > 0);
         limit = MIN(allocated - 1, MAX(s->manager->config.line_max, STDOUT_STREAM_SETUP_PROTOCOL_LINE_MAX));
         assert(s->length <= limit);
         iovec = IOVEC_MAKE(s->buffer + s->length, limit - s->length);