Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Jul 2019 15:07:19 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r349730 - head/contrib/elftoolchain/elfcopy
Message-ID:  <201907041507.x64F7J3w084609@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Thu Jul  4 15:07:19 2019
New Revision: 349730
URL: https://svnweb.freebsd.org/changeset/base/349730

Log:
  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

Modified:
  head/contrib/elftoolchain/elfcopy/sections.c

Modified: head/contrib/elftoolchain/elfcopy/sections.c
==============================================================================
--- head/contrib/elftoolchain/elfcopy/sections.c	Thu Jul  4 14:51:44 2019	(r349729)
+++ head/contrib/elftoolchain/elfcopy/sections.c	Thu Jul  4 15:07:19 2019	(r349730)
@@ -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;
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201907041507.x64F7J3w084609>