Blob Blame History Raw
From fa61c840ba6be18c6579b247605634c1e2a320f8 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 9 Mar 2017 22:13:01 +0100
Subject: [PATCH] generateBuildIDs: Fix error handling.

commit e6bdf7 made it so that we don't give a warning or error message
for non-kernel ET_REL object files with missing or bad build-ids. But
we still (unintentionally) failed generateBuildIDs which made us skip
generating the cpioList causing an obscure failure message.

Move the sanity check earlier so we don't process such object files at
all. And if there is any real error from generateBuildIDs give a clear
error message and explicitly set processingFailed.

Signed-off-by: Mark Wielaard <mark@klomp.org>
(cherry picked from commit 5bd77379eee167fbdb8d139dc9ab2da74f2a544f)
---
 build/files.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/build/files.c b/build/files.c
index b19abf299..fef0c6960 100644
--- a/build/files.c
+++ b/build/files.c
@@ -1686,10 +1686,16 @@ static int generateBuildIDs(FileList fl)
 	if (lstat(flp->diskPath, &sbuf) == 0 && S_ISREG (sbuf.st_mode)) {
 	    int fd = open (flp->diskPath, O_RDONLY);
 	    if (fd >= 0) {
+		/* Only real ELF files, that are ET_EXEC, ET_DYN or
+		   kernel modules (ET_REL files with names ending in .ko)
+		   should have build-ids. */
 		GElf_Ehdr ehdr;
 		Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
 		if (elf != NULL && elf_kind(elf) == ELF_K_ELF
-		    && gelf_getehdr(elf, &ehdr) != NULL) {
+		    && gelf_getehdr(elf, &ehdr) != NULL
+		    && (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN
+			|| (ehdr.e_type == ET_REL
+			    && rpmFileHasSuffix (flp->diskPath, ".ko")))) {
 		    const void *build_id;
 		    ssize_t len = dwelf_elf_gnu_build_id (elf, &build_id);
 		    /* len == -1 means error. Zero means no
@@ -1738,11 +1744,6 @@ static int generateBuildIDs(FileList fl)
 				   _("error reading build-id in %s: %s\n"),
 				   flp->diskPath, elf_errmsg (-1));
 			} else if (len == 0) {
-			    /* Only ET_EXEC, ET_DYN or kernel modules
-			       have build-ids. */
-			    if (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN
-				|| (ehdr.e_type == ET_REL
-				    && rpmFileHasSuffix (flp->diskPath, ".ko")))
 			      rpmlog(terminate ? RPMLOG_ERR : RPMLOG_WARNING,
 				     _("Missing build-id in %s\n"),
 				     flp->diskPath);
@@ -2354,8 +2355,11 @@ static rpmRC processPackageFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
 	goto exit;
 
 #if HAVE_LIBDW
-    if (generateBuildIDs (&fl) != 0)
+    if (generateBuildIDs (&fl) != 0) {
+	rpmlog(RPMLOG_ERR, _("Generating build-id links failed\n"));
+	fl.processingFailed = 1;
 	goto exit;
+    }
 #endif
 
     /* Verify that file attributes scope over hardlinks correctly. */