aboutsummaryrefslogtreecommitdiffstats
path: root/main/uclibc/0001-ldd-segfault-fix.patch
blob: 4384fa548c6a3bcb7c0167c77a768f0362f39261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
From f29b6882327573ec4e694c1c852307c957d544b9 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 5 May 2009 14:10:42 +0000
Subject: [PATCH] ldd segfault fix

Fixes ldd segfault on this testcase:

extern void _dl_getenv(void);
void foo(void)
{
	printf("foo: %x\n", &_dl_getenv);
}

linked as -shared
---
 utils/ldd.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/utils/ldd.c b/utils/ldd.c
index 1f1dc25..2cd173c 100644
--- a/utils/ldd.c
+++ b/utils/ldd.c
@@ -576,18 +576,20 @@ static struct library *find_elf_interpreter(ElfW(Ehdr) *ehdr)
 				}
 				newlib->name = NULL;
 				newlib->path = NULL;
-				return NULL;
+				break;
 			}
 		}
-		if (newlib == NULL)
+		if (newlib == NULL) {
 			newlib = malloc(sizeof(struct library));
+			if (newlib)
+				newlib->next = NULL;
+		}
 		if (!newlib)
 			return NULL;
 		newlib->name = malloc(strlen(s) + 1);
 		strcpy(newlib->name, s);
 		newlib->path = strdup(newlib->name);
 		newlib->resolved = 1;
-		newlib->next = NULL;
 
 #if 0
 		/*printf("find_elf_interpreter is adding '%s' to '%s'\n", newlib->name, newlib->path); */
-- 
1.6.2.3