View Issue Details

IDProjectCategoryView StatusLast Update
0000013file[All Projects] Generalpublic2018-08-01 09:04
ReportercbiedlAssigned Tochristos 
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000013: ELF: Please handle files without program headers gracefully
DescriptionDebian bug: https://bugs.debian.org/882310

libmagic reports files without a program header as "corrupted program header size". As mentioned in that report, there used to be a fix for this in Redhat┬╣ some whopping 15 years ago, but it apparently never was upstreamed. I took the liberty to forward-port it to 5.33

┬╣ https://bugzilla.redhat.com/attachment.cgi?id=95833&action=diff&context=patch&collapsed=&headers=1&format=raw
Steps To ReproduceSee the Debian bug
TagsNo tags attached.
Attach Tags

Activities

cbiedl

2018-07-22 10:51

reporter  

0001-ELF-Handle-files-without-program-headers-gracefully.patch (1,565 bytes)
From 5960278b8958aa7ed5fb9730e466e632ad5a21a5 Mon Sep 17 00:00:00 2001
From: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
Date: Sun, 22 Jul 2018 12:42:09 +0200
Subject: [PATCH] ELF: Handle files without program headers gracefully

Forward-ported from https://bugzilla.redhat.com/show_bug.cgi?id=109509
---
 src/readelf.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/readelf.c b/src/readelf.c
index db0b35a5..0441da41 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -352,6 +352,11 @@ dophn_core(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 	off_t ph_off = off;
 	int ph_num = num;
 
+	if (num == 0) {
+		if (file_printf(ms, ", no program header") == -1)
+			return -1;
+		return 0;
+	}
 	if (size != xph_sizeof) {
 		if (file_printf(ms, ", corrupted program header size") == -1)
 			return -1;
@@ -1278,6 +1283,11 @@ doshn(struct magic_set *ms, int clazz, int swap, int fd, off_t off, int num,
 	char name[50];
 	ssize_t namesize;
 
+	if (num == 0) {
+		if (file_printf(ms, ", no section header") == -1)
+			return -1;
+		return 0;
+	}
 	if (size != xsh_sizeof) {
 		if (file_printf(ms, ", corrupted section header size") == -1)
 			return -1;
@@ -1549,6 +1559,11 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
 	ssize_t bufsize;
 	size_t offset, align, len;
 	
+	if (num == 0) {
+		if (file_printf(ms, ", no program header") == -1)
+			return -1;
+		return 0;
+	}
 	if (size != xph_sizeof) {
 		if (file_printf(ms, ", corrupted program header size") == -1)
 			return -1;
-- 
2.18.0

christos

2018-07-25 06:12

manager   ~0000013

Applied, thanks!

christos

2018-08-01 09:04

manager   ~0000027

feedback timeout

Issue History

Date Modified Username Field Change
2018-07-22 10:51 cbiedl New Issue
2018-07-22 10:51 cbiedl File Added: 0001-ELF-Handle-files-without-program-headers-gracefully.patch
2018-07-25 06:12 christos Assigned To => christos
2018-07-25 06:12 christos Status new => assigned
2018-07-25 06:12 christos Status assigned => feedback
2018-07-25 06:12 christos Note Added: 0000013
2018-08-01 09:04 christos Status feedback => resolved
2018-08-01 09:04 christos Resolution open => fixed
2018-08-01 09:04 christos Note Added: 0000027