Re: [hackers] [sbase] tar: check if reallocarray failed

From: Laslo Hunhold <dev_AT_frign.de>
Date: Sun, 18 Jul 2021 19:03:21 +0200

On Sat, 17 Jul 2021 21:04:04 +0200
Hiltjo Posthuma <hiltjo_AT_codemadness.org> wrote:

Dear Hiltjo,

> The patch below is for sbase tar:
>
> From 2eec3e07a5bd1ed1fa41ca02865297ab7d8b5fa8 Mon Sep 17 00:00:00 2001
> From: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
> Date: Sat, 17 Jul 2021 21:03:27 +0200
> Subject: [PATCH] tar: check if reallocarray failed
>
> ---
> tar.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tar.c b/tar.c
> index b74c134..122f30a 100644
> --- a/tar.c
> +++ b/tar.c
> _AT_@ -78,7 +78,7 @@ static const char *filtertools[] = {
> static void
> pushdirtime(char *name, time_t mtime)
> {
> - dirtimes = reallocarray(dirtimes, dirtimeslen + 1,
> sizeof(*dirtimes));
> + dirtimes = ereallocarray(dirtimes, dirtimeslen + 1,
> sizeof(*dirtimes)); dirtimes[dirtimeslen].name = strdup(name);
> dirtimes[dirtimeslen].mtime = mtime;
> dirtimeslen++;

ah yes, good catch! While at it, we might also want to check the
strdup() in the consecutive line, right?

With best regards

Laslo
Received on Sun Jul 18 2021 - 19:03:21 CEST

This archive was generated by hypermail 2.3.0 : Sun Jul 18 2021 - 19:12:33 CEST