From 66b16d12d89e04b37ddd7aa48668e0f8568d57b6 Mon Sep 17 00:00:00 2001 From: Nicolas Williams Date: Wed, 21 Dec 2022 22:46:07 -0600 Subject: [PATCH] roken: Use calloc() for overflow det. in hex_encode Using calloc() means setting errno on overflow instead of not. --- lib/roken/hex.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/roken/hex.c b/lib/roken/hex.c index cc47fa4d5..5cd202603 100644 --- a/lib/roken/hex.c +++ b/lib/roken/hex.c @@ -58,13 +58,7 @@ hex_encode(const void *data, size_t size, char **str) size_t i; char *p; - /* check for overflow */ - if (size * 2 < size) { - *str = NULL; - return -1; - } - - p = malloc(size * 2 + 1); + p = calloc(size + 1, 2); if (p == NULL) { *str = NULL; return -1;