From: Luca Boccassi Date: Sat, 28 Mar 2026 22:46:35 +0000 (+0000) Subject: journald: add assert for allocated buffer size X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea1e81e1179d0a50ff4348b40d64a15870ccdff8;p=thirdparty%2Fsystemd.git journald: add assert for allocated buffer size 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 --- diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index 677fb93b759..ee903755cf7 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -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);