logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 437351928c485ffd3485fc1958bf9a7067150bc3
parent 89079e2ff003563e8b1a63a8c6233b115ff5b05b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Mon, 23 Sep 2024 05:23:04 +0200

cmd/printf: check against overflow prior to calloc

Diffstat:

Mcmd/printf.c4+++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cmd/printf.c b/cmd/printf.c @@ -38,6 +38,7 @@ #define _POSIX_C_SOURCE 200809L +#include <assert.h> #include <ctype.h> #include <err.h> #include <errno.h> @@ -496,7 +497,8 @@ mknum(char *str, char ch) len = strlen(str) + 2; if(len > copy_size) { - newlen = ((len + 1023) >> 10) << 10; + newlen = len + 1023; + assert(newlen != 0); if((newcopy = realloc(copy, newlen)) == NULL) { warnx("warning: %s", strerror(ENOMEM));