From: Tobias Stoeckmann Date: Wed, 18 Dec 2024 09:37:14 +0000 (+0100) Subject: strbuf: Extend strbuf_reserve_extra size check X-Git-Tag: v34~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=235a38bf51ee21e73de0110d7d22894f308920b9;p=thirdparty%2Fkmod.git strbuf: Extend strbuf_reserve_extra size check 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 Link: https://github.com/kmod-project/kmod/pull/268 Signed-off-by: Lucas De Marchi --- diff --git a/shared/strbuf.c b/shared/strbuf.c index 0dd7a5b0..332dbd33 100644 --- a/shared/strbuf.c +++ b/shared/strbuf.c @@ -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)