summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorKurt Miller <kurt@cvs.openbsd.org>2008-06-25 02:51:09 +0000
committerKurt Miller <kurt@cvs.openbsd.org>2008-06-25 02:51:09 +0000
commitd5e6b24a6005f59e338162671f0277dbf919cb16 (patch)
tree35f76d0bd687aad3a781066b387247b164fec1ad /libexec
parent435c087049f33ae76a94e5413060193fea96667e (diff)
Make ldd grok pie binaries.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ld.so/ldd/ldd.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/libexec/ld.so/ldd/ldd.c b/libexec/ld.so/ldd/ldd.c
index eac4a7d0eba..bccc9b7a9e8 100644
--- a/libexec/ld.so/ldd/ldd.c
+++ b/libexec/ld.so/ldd/ldd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldd.c,v 1.12 2007/05/29 04:47:17 jason Exp $ */
+/* $OpenBSD: ldd.c,v 1.13 2008/06/25 02:51:08 kurt Exp $ */
/*
* Copyright (c) 2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -94,11 +94,10 @@ doit(char *name)
{
Elf_Ehdr ehdr;
Elf_Phdr *phdr;
- int fd, i, size, status;
+ int fd, i, size, status, interp=0;
char buf[MAXPATHLEN];
void * dlhandle;
-
if ((fd = open(name, O_RDONLY)) < 0) {
warn("%s", name);
return 1;
@@ -117,7 +116,24 @@ doit(char *name)
return 1;
}
- if (ehdr.e_type == ET_DYN) {
+ size = ehdr.e_phnum * sizeof(Elf_Phdr);
+ if ((phdr = malloc(size)) == NULL)
+ err(1, "malloc");
+
+ if (pread(fd, phdr, size, ehdr.e_phoff) != size) {
+ warn("read(%s)", name);
+ close(fd);
+ free(phdr);
+ return 1;
+ }
+
+ for (i = 0; i < ehdr.e_phnum; i++)
+ if (phdr[i].p_type == PT_INTERP) {
+ interp = 1;
+ break;
+ }
+
+ if (ehdr.e_type == ET_DYN && !interp) {
printf("%s:\n", name);
if (realpath(name, buf) == NULL) {
warn("realpath(%s)", name);
@@ -129,22 +145,10 @@ doit(char *name)
return 1;
}
close(fd);
+ free(phdr);
return 0;
}
- size = ehdr.e_phnum * sizeof(Elf_Phdr);
- if ((phdr = malloc(size)) == NULL)
- err(1, "malloc");
-
- if (pread(fd, phdr, size, ehdr.e_phoff) != size) {
- warn("read(%s)", name);
- close(fd);
- free(phdr);
- return 1;
- }
- for (i = 0; i < ehdr.e_phnum; i++)
- if (phdr[i].p_type == PT_DYNAMIC)
- break;
close(fd);
free(phdr);