From 8a8d45cb734eb8087773988cafee3a15906e7f52 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 4 Sep 2024 19:21:04 +0900 Subject: [PATCH] Fix potential overflow --- lib/nghttp3_qpack.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/nghttp3_qpack.c b/lib/nghttp3_qpack.c index 603d57d..c296ad3 100644 --- a/lib/nghttp3_qpack.c +++ b/lib/nghttp3_qpack.c @@ -1116,12 +1116,12 @@ static int reserve_buf(nghttp3_buf *buf, size_t extra_size, n = nghttp3_max_size(n, nghttp3_buf_cap(buf) + extra_size - left); /* Check whether we are requesting too much memory */ - if (n > UINT32_MAX) { + if (n > (1u << 31)) { return NGHTTP3_ERR_NOMEM; } #ifndef WIN32 - n = 1 << (32 - __builtin_clz((uint32_t)n - 1)); + n = 1u << (32 - __builtin_clz((uint32_t)n - 1)); #else /* WIN32 */ /* Round up to the next highest power of 2 from Bit Twiddling Hacks */