Skip to content

Commit

Permalink
Merge pull request #254 from ngtcp2/amend-253
Browse files Browse the repository at this point in the history
Fix potential overflow
  • Loading branch information
tatsuhiro-t committed Sep 4, 2024
2 parents 99ba689 + 8a8d45c commit 7473d2f
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/nghttp3_qpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 7473d2f

Please sign in to comment.