logo

utils-std

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

cmd/paste: check against overflow prior to calloc

Diffstat:

Mcmd/paste.c2++
1 file changed, 2 insertions(+), 0 deletions(-)

diff --git a/cmd/paste.c b/cmd/paste.c @@ -36,6 +36,7 @@ #include <errno.h> #include <limits.h> #include <locale.h> +#include <stdint.h> // SIZE_MAX #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -71,6 +72,7 @@ main(int argc, char *argv[]) arg = optarg; len = mbsrtowcs(NULL, &arg, 0, NULL); if(len == (size_t)-1) err(1, "error: delimiters"); + if(len == SIZE_MAX) err(1, NULL); warg = calloc((len + 1), sizeof(*warg)); if(warg == NULL) err(1, NULL); arg = optarg;