From e6f0df2b205a873c4a828ea1277c5b5218cd55b0 Mon Sep 17 00:00:00 2001 From: "Andrey A. Chernov" Date: Fri, 15 Dec 2000 13:20:43 +0000 Subject: [PATCH] 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 --- usr.bin/ldd/ldd.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c index e272b6b3a257..cf9ebde6fc35 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);