bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC PATCH 1/2] elf: Port ldconfig away from stack-allocated paths


From: Florian Weimer
Subject: Re: [RFC PATCH 1/2] elf: Port ldconfig away from stack-allocated paths
Date: Thu, 25 May 2023 10:07:55 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)

* Sergey Bugaev:

> diff --git a/elf/ldconfig.c b/elf/ldconfig.c
> index 2fc45ad8..e643dd57 100644
> --- a/elf/ldconfig.c
> +++ b/elf/ldconfig.c

> -       len = strlen (dir_name) + strlen (direntry->d_name) + 2;
> -       if (len > real_file_name_len)
> -         {
> -           real_file_name_len = len;
> -           real_file_name = alloca (real_file_name_len);
> -         }
> -       sprintf (real_file_name, "%s/%s", dir_name, direntry->d_name);
> +       if (asprintf (&real_file_name, "%s/%s",
> +                     dir_name, direntry->d_name) < 0)
> +         error (EXIT_FAILURE, errno, _("Could not form library path"));
>       }
> +      else
> +     real_file_name = file_name;

Maybe use xstrdup (file_name) here and free unconditionally below?
It makes it easier to analyze the code for use-after-free errors.

Rest looks okay.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian




reply via email to

[Prev in Thread] Current Thread [Next in Thread]