summaryrefslogtreecommitdiffstats
path: root/usr.bin/ldd
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2000-12-15 13:20:43 +0000
committerache <ache@FreeBSD.org>2000-12-15 13:20:43 +0000
commitf15d921e9eff691ff94f40f1490b10cd0ab78d65 (patch)
treec9f389bf0d471de8f5c8c91a076f01fd3a47d5d9 /usr.bin/ldd
parent17397c2789732b0e9c12a4a4af0b3f180125e11c (diff)
downloadFreeBSD-src-f15d921e9eff691ff94f40f1490b10cd0ab78d65.zip
FreeBSD-src-f15d921e9eff691ff94f40f1490b10cd0ab78d65.tar.gz
Fix lseek args order (PR 23549)
Catch and report lseek errors too While reading header don't attempt to continue reading if some IO operation fails PR: 23549
Diffstat (limited to 'usr.bin/ldd')
-rw-r--r--usr.bin/ldd/ldd.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c
index e272b6b..cf9ebde 100644
--- a/usr.bin/ldd/ldd.c
+++ b/usr.bin/ldd/ldd.c
@@ -145,21 +145,24 @@ char *argv[];
Elf_Phdr phdr;
int dynamic = 0, i;
- lseek(fd, 0, SEEK_SET);
- if (read(fd, &ehdr, sizeof ehdr) != sizeof ehdr) {
+ if (lseek(fd, 0, SEEK_SET) == -1 ||
+ read(fd, &ehdr, sizeof ehdr) != sizeof ehdr ||
+ lseek(fd, ehdr.e_phoff, SEEK_SET) == -1
+ ) {
warnx("%s: can't read program header", *argv);
file_ok = 0;
- }
- lseek(fd, 0, ehdr.e_phoff);
- for (i = 0; i < ehdr.e_phnum; i++) {
- if (read(fd, &phdr, ehdr.e_phentsize)
- != sizeof phdr) {
- warnx("%s: can't read program header",
- *argv);
- file_ok = 0;
+ } else {
+ for (i = 0; i < ehdr.e_phnum; i++) {
+ if (read(fd, &phdr, ehdr.e_phentsize)
+ != sizeof phdr) {
+ warnx("%s: can't read program header",
+ *argv);
+ file_ok = 0;
+ break;
+ }
+ if (phdr.p_type == PT_DYNAMIC)
+ dynamic = 1;
}
- if (phdr.p_type == PT_DYNAMIC)
- dynamic = 1;
}
if (!dynamic) {
warnx("%s: not a dynamic executable", *argv);
OpenPOWER on IntegriCloud