elfcopy: Clear errors after fetching the shstrtab index.

Otherwise a future call to elf_errno() will return a non-zero value.
update_shdr(), for example, treats any errors associated with the ELF
descriptor as fatal.  Clear the error per the first example in
elf_errmsg.3.

Convert to elf_getshdrstrndx() while here since elf_getshstrndx() is
apparently deprecated.

Reported by:	royger
Reviewed by:	emaste
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D20852
This commit is contained in:
Mark Johnston 2019-07-04 15:07:19 +00:00
parent 3b53f994ea
commit 0070b575f4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=349730

View File

@ -1403,7 +1403,7 @@ init_shstrtab(struct elfcopy *ecp)
struct section *s;
size_t indx, sizehint;
if (elf_getshstrndx(ecp->ein, &indx) != 0) {
if (elf_getshdrstrndx(ecp->ein, &indx) == 0) {
shstrtab = elf_getscn(ecp->ein, indx);
if (shstrtab == NULL)
errx(EXIT_FAILURE, "elf_getscn failed: %s",
@ -1413,6 +1413,8 @@ init_shstrtab(struct elfcopy *ecp)
elf_errmsg(-1));
sizehint = shdr.sh_size;
} else {
/* Clear the error from elf_getshdrstrndx(3). */
(void)elf_errno();
sizehint = 0;
}