mkhtemp rand: fix theoretical integer overflow

extremely theoretical, with a T. T for theoretical.

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-03-26 09:04:30 +00:00
parent d6087901c1
commit 8e8f7bced4
+4 -1
View File
@@ -126,7 +126,7 @@ mkrstr(size_t n) /* emulates spkmodem-decode */
if (n == 0)
err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request");
if (n == SIZE_MAX)
if (n >= SIZE_MAX - 1)
err_no_cleanup(0, EOVERFLOW, "mkrbuf: overflow");
if (if_err((s = mkrbuf(n + 1)) == NULL, EFAULT))
@@ -149,6 +149,9 @@ mkrbuf(size_t n)
if (n == 0)
err_no_cleanup(0, EPERM, "mkrbuf: zero-byte request");
if (n >= SIZE_MAX - 1)
err_no_cleanup(0, EOVERFLOW, "integer overflow in mkrbuf");
if ((buf = malloc(n)) == NULL)
err_no_cleanup(0, ENOMEM, "mkrbuf: malloc");