sudo_lbuf_expand: limit allocation to UINT_MAX

This commit is contained in:
Todd C. Miller
2023-07-03 19:46:37 -06:00
parent d3dc70ab62
commit f5eb1e0550

View File

@@ -23,10 +23,11 @@
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "sudo_compat.h"
#include "sudo_debug.h"
@@ -82,7 +83,7 @@ sudo_lbuf_expand(struct sudo_lbuf *lbuf, unsigned int extra)
size_t new_size = sudo_pow2_roundup(lbuf->len + extra + 1);
char *new_buf;
if (new_size < lbuf->size) {
if (new_size > UINT_MAX || new_size < lbuf->size) {
errno = ENOMEM;
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"integer overflow updating lbuf->size");