From 64d6d400f601dd20f65d66539fdecf536e4d52b5 Mon Sep 17 00:00:00 2001 From: Thomas Weißschuh Date: Fri, 22 Sep 2023 11:56:42 +0200 Subject: treewide: use (x)reallocarray() when applicable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit reallocarray() prevents overflow of the multiplication. It also avoids issues with operator precedence like in libmount/src/context.c: pids = realloc(cxt->children, sizeof(pid_t) * cxt->nchildren + 1); This only allocated one additional byte, and not enough space for another child. Signed-off-by: Thomas Weißschuh --- lib/loopdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/loopdev.c') diff --git a/lib/loopdev.c b/lib/loopdev.c index 323f7bd50d..dae499f256 100644 --- a/lib/loopdev.c +++ b/lib/loopdev.c @@ -495,7 +495,7 @@ static int loop_scandir(const char *dirname, int **ary, int hasprefix) arylen += 1; - tmp = realloc(*ary, arylen * sizeof(int)); + tmp = reallocarray(*ary, arylen, sizeof(int)); if (!tmp) { free(*ary); *ary = NULL; -- cgit 1.2.3-korg