From f29b6882327573ec4e694c1c852307c957d544b9 Mon Sep 17 00:00:00 2001 From: Natanael Copa 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