[PATCH] size: Fix deref-of-null in handle_ar() function
Sam James
sam@gentoo.org
Mon Jul 1 20:54:46 GMT 2024
Maks Mishin <maks.mishinfz@gmail.com> writes:
> Pointer, returned from function 'elf_getarhdr' at size.c:362,
> may be NULL and is dereferenced at size.c:367.
>
Your other patch has "Found by RASU JSC." but the rest don't. Are they
all found by it? If so, please say that.
(Also, consider sending the fixes as a series if they're related/from
the same analyser tool batch.)
> Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
> ---
> src/size.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/src/size.c b/src/size.c
> index ff8ca075..d6bce203 100644
> --- a/src/size.c
> +++ b/src/size.c
> @@ -361,6 +361,16 @@ handle_ar (int fd, Elf *elf, const char *prefix, const char *fname)
> /* The the header for this element. */
> Elf_Arhdr *arhdr = elf_getarhdr (subelf);
>
> + if (arhdr == NULL)
> + {
> + printf ("cannot get archive header in '%s': %s\n",
> + fname, elf_errmsg (-1));
> + elf_end (subelf);
> + elf_end (elf);
> + close (fd);
> + return 1;
> + }
> +
> if (elf_kind (subelf) == ELF_K_ELF)
> handle_elf (subelf, new_prefix, arhdr->ar_name);
> else if (likely (elf_kind (subelf) == ELF_K_AR))
More information about the Elfutils-devel
mailing list