diff options
author | Mark Johnston <markj@FreeBSD.org> | 2019-07-04 15:07:19 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2019-07-04 15:07:19 +0000 |
commit | 0070b575f47d9fa116f7c4367faed3e1b5f88555 (patch) | |
tree | 6c32c6dc160951b428b6e0f7f12bd7575797ac52 /contrib/elftoolchain | |
parent | 3b53f994ea89486d859e6bb4144b19e07ea77cea (diff) | |
download | src-0070b575f47d9fa116f7c4367faed3e1b5f88555.tar.gz src-0070b575f47d9fa116f7c4367faed3e1b5f88555.zip |
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
Notes
Notes:
svn path=/head/; revision=349730
Diffstat (limited to 'contrib/elftoolchain')
-rw-r--r-- | contrib/elftoolchain/elfcopy/sections.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/contrib/elftoolchain/elfcopy/sections.c b/contrib/elftoolchain/elfcopy/sections.c index 2bd094d2bfbe..c2f40dc49ac9 100644 --- a/contrib/elftoolchain/elfcopy/sections.c +++ b/contrib/elftoolchain/elfcopy/sections.c @@ -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; } |