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
This commit is contained in:
Andrey A. Chernov 2000-12-15 13:20:43 +00:00
parent 874d21b468
commit e6f0df2b20
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=70049

View File

@ -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);