teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0014-generateBuildIDs-Fix-error-handling.patch

Mark Wielaard 1a7230
From 7e053a6d843b141fc6b5a89d050082233ed034d6 Mon Sep 17 00:00:00 2001
Mark Wielaard 1a7230
From: Mark Wielaard <mark@klomp.org>
Mark Wielaard 1a7230
Date: Thu, 9 Mar 2017 22:13:01 +0100
Mark Wielaard 1a7230
Subject: [PATCH] generateBuildIDs: Fix error handling.
Mark Wielaard 1a7230
Mark Wielaard 1a7230
commit e6bdf7 made it so that we don't give a warning or error message
Mark Wielaard 1a7230
for non-kernel ET_REL object files with missing or bad build-ids. But
Mark Wielaard 1a7230
we still (unintentionally) failed generateBuildIDs which made us skip
Mark Wielaard 1a7230
generating the cpioList causing an obscure failure message.
Mark Wielaard 1a7230
Mark Wielaard 1a7230
Move the sanity check earlier so we don't process such object files at
Mark Wielaard 1a7230
all. And if there is any real error from generateBuildIDs give a clear
Mark Wielaard 1a7230
error message and explicitly set processingFailed.
Mark Wielaard 1a7230
Mark Wielaard 1a7230
Signed-off-by: Mark Wielaard <mark@klomp.org>
Mark Wielaard 1a7230
---
Mark Wielaard 1a7230
 build/files.c | 18 +++++++++++-------
Mark Wielaard 1a7230
 1 file changed, 11 insertions(+), 7 deletions(-)
Mark Wielaard 1a7230
Mark Wielaard 1a7230
diff --git a/build/files.c b/build/files.c
Mark Wielaard 1a7230
index b19abf2..fef0c69 100644
Mark Wielaard 1a7230
--- a/build/files.c
Mark Wielaard 1a7230
+++ b/build/files.c
Mark Wielaard 1a7230
@@ -1686,10 +1686,16 @@ static int generateBuildIDs(FileList fl)
Mark Wielaard 1a7230
 	if (lstat(flp->diskPath, &sbuf) == 0 && S_ISREG (sbuf.st_mode)) {
Mark Wielaard 1a7230
 	    int fd = open (flp->diskPath, O_RDONLY);
Mark Wielaard 1a7230
 	    if (fd >= 0) {
Mark Wielaard 1a7230
+		/* Only real ELF files, that are ET_EXEC, ET_DYN or
Mark Wielaard 1a7230
+		   kernel modules (ET_REL files with names ending in .ko)
Mark Wielaard 1a7230
+		   should have build-ids. */
Mark Wielaard 1a7230
 		GElf_Ehdr ehdr;
Mark Wielaard 1a7230
 		Elf *elf = elf_begin (fd, ELF_C_READ, NULL);
Mark Wielaard 1a7230
 		if (elf != NULL && elf_kind(elf) == ELF_K_ELF
Mark Wielaard 1a7230
-		    && gelf_getehdr(elf, &ehdr) != NULL) {
Mark Wielaard 1a7230
+		    && gelf_getehdr(elf, &ehdr) != NULL
Mark Wielaard 1a7230
+		    && (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN
Mark Wielaard 1a7230
+			|| (ehdr.e_type == ET_REL
Mark Wielaard 1a7230
+			    && rpmFileHasSuffix (flp->diskPath, ".ko")))) {
Mark Wielaard 1a7230
 		    const void *build_id;
Mark Wielaard 1a7230
 		    ssize_t len = dwelf_elf_gnu_build_id (elf, &build_id);
Mark Wielaard 1a7230
 		    /* len == -1 means error. Zero means no
Mark Wielaard 1a7230
@@ -1738,11 +1744,6 @@ static int generateBuildIDs(FileList fl)
Mark Wielaard 1a7230
 				   _("error reading build-id in %s: %s\n"),
Mark Wielaard 1a7230
 				   flp->diskPath, elf_errmsg (-1));
Mark Wielaard 1a7230
 			} else if (len == 0) {
Mark Wielaard 1a7230
-			    /* Only ET_EXEC, ET_DYN or kernel modules
Mark Wielaard 1a7230
-			       have build-ids. */
Mark Wielaard 1a7230
-			    if (ehdr.e_type == ET_EXEC || ehdr.e_type == ET_DYN
Mark Wielaard 1a7230
-				|| (ehdr.e_type == ET_REL
Mark Wielaard 1a7230
-				    && rpmFileHasSuffix (flp->diskPath, ".ko")))
Mark Wielaard 1a7230
 			      rpmlog(terminate ? RPMLOG_ERR : RPMLOG_WARNING,
Mark Wielaard 1a7230
 				     _("Missing build-id in %s\n"),
Mark Wielaard 1a7230
 				     flp->diskPath);
Mark Wielaard 1a7230
@@ -2354,8 +2355,11 @@ static rpmRC processPackageFiles(rpmSpec spec, rpmBuildPkgFlags pkgFlags,
Mark Wielaard 1a7230
 	goto exit;
Mark Wielaard 1a7230
 
Mark Wielaard 1a7230
 #if HAVE_LIBDW
Mark Wielaard 1a7230
-    if (generateBuildIDs (&fl) != 0)
Mark Wielaard 1a7230
+    if (generateBuildIDs (&fl) != 0) {
Mark Wielaard 1a7230
+	rpmlog(RPMLOG_ERR, _("Generating build-id links failed\n"));
Mark Wielaard 1a7230
+	fl.processingFailed = 1;
Mark Wielaard 1a7230
 	goto exit;
Mark Wielaard 1a7230
+    }
Mark Wielaard 1a7230
 #endif
Mark Wielaard 1a7230
 
Mark Wielaard 1a7230
     /* Verify that file attributes scope over hardlinks correctly. */
Mark Wielaard 1a7230
-- 
Mark Wielaard 1a7230
1.8.3.1
Mark Wielaard 1a7230