]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
strbuf: Extend strbuf_reserve_extra size check
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 18 Dec 2024 09:37:14 +0000 (10:37 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Thu, 2 Jan 2025 20:35:52 +0000 (14:35 -0600)
Make sure that alignment to BUF_STEP won't overflow if excessively
huge amount of memory is requested to be reserved.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/268
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
shared/strbuf.c

index 0dd7a5b0dc9522a9a62bf4764f2cc117386adab5..332dbd339857ac6f28aa54ec3ad517d3f575f5f7 100644 (file)
@@ -36,7 +36,7 @@ static bool buf_realloc(struct strbuf *buf, size_t sz)
 
 bool strbuf_reserve_extra(struct strbuf *buf, size_t n)
 {
-       if (uaddsz_overflow(buf->used, n, &n))
+       if (uaddsz_overflow(buf->used, n, &n) || n > SIZE_MAX - BUF_STEP)
                return false;
 
        if (n <= buf->size)