sync code with last fixes and improvements from OpenBSD

This commit is contained in:
purplerain 2023-07-20 23:56:46 +00:00
parent f57be82572
commit 58b04bcee7
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
468 changed files with 9958 additions and 7882 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ldd.c,v 1.22 2017/10/27 16:47:08 mpi Exp $ */
/* $OpenBSD: ldd.c,v 1.23 2023/07/13 19:04:50 jasper Exp $ */
/*
* Copyright (c) 2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@ -117,19 +117,25 @@ doit(char *name)
close(fd);
return 1;
}
if (read(fd, &ehdr, sizeof(ehdr)) < 0) {
warn("read(%s)", name);
close(fd);
return 1;
}
if (memcmp(ehdr.e_ident, ELFMAG, SELFMAG) ||
ehdr.e_machine != ELF_TARG_MACH) {
if (!IS_ELF(ehdr) || ehdr.e_machine != ELF_TARG_MACH) {
warnx("%s: not an ELF executable", name);
close(fd);
return 1;
}
if (ehdr.e_phnum == 0 || ehdr.e_phentsize == 0) {
warnx("%s: missing program header", name);
close(fd);
return 1;
}
if ((phdr = reallocarray(NULL, ehdr.e_phnum, sizeof(Elf_Phdr))) == NULL)
err(1, "reallocarray");
size = ehdr.e_phnum * sizeof(Elf_Phdr);