libelf: find 1st section instead of assuming
authorJohn Ogness <john.ogness@linutronix.de>
Thu, 23 Jun 2016 14:03:58 +0000 (16:03 +0200)
committerMark Wielaard <mjw@redhat.com>
Tue, 28 Jun 2016 18:19:24 +0000 (20:19 +0200)
commit96e140f6687922606657a76f185a73cf47908ef2
tree21b2be7ae43403b06511775c0ab5cfa4937af581
parent9a36c9226c4a237208a7735f0e6a6fd1eefb60ab
libelf: find 1st section instead of assuming

When getting section headers it is assumed that the first section
is on the first section list. However, it is possible that the
first section list only contains the zeroth section, in which
case either illegal memory access occurs or elf_nextscn()
erroneously returns NULL.

With this patch, checks are added to avoid the illegal memory
access and (if available) the second section list is looked at
to find the first section.

A new test emptyfile is added that tests adding a section to
and "empty" ELF file 32/64 class with ELF_C_RDWR[_MMAP].

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf/ChangeLog
libelf/elf32_updatenull.c
libelf/elf_nextscn.c
tests/ChangeLog
tests/Makefile.am
tests/emptyfile.c [new file with mode: 0644]