This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: [PATCH] Do without union of variable length arrays.
- From: Alexander Cherepanov <ch3root at openwall dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Wed, 07 Oct 2015 02:38:45 +0300
- Subject: Re: [PATCH] Do without union of variable length arrays.
On 2015-10-07 02:17, Chih-hung Hsieh wrote:
> + if (unlikely (phnum >
> + SIZE_MAX / MAX (sizeof (Elf32_Phdr), sizeof
(Elf64_Phdr))))
> + return DWFL_E_NOMEM;
> + const size_t phdrs_bytes =
> + phnum * MAX (sizeof (Elf32_Phdr), sizeof (Elf64_Phdr));
> + void *phdrs = malloc (phdrs_bytes);
> + Elf32_Phdr (*p32)[phnum] = phdrs;
> + Elf64_Phdr (*p64)[phnum] = phdrs;
If the amount of allocated memory is explicitly calculated as above it's
potentially possible to use exact amount, e.g. phnum * sizeof
(Elf32_Phdr) for p32 (and assign NULL to p64) or phnum * MAX (sizeof
(Elf64_Phdr) for p64 (and assign NULL to p32). I'm not familiar with the
codebase enough to judge if it's feasible. Just to make sure that this
aspect is not overlooked.
--
Alexander Cherepanov