[PATCH] Do without union of variable length arrays.
Alexander Cherepanov
ch3root at openwall.com
Tue Oct 6 23:38:45 UTC 2015
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
More information about the elfutils-devel
mailing list