X-Git-Url: https://pd.if.org/git/?p=zpackage;a=blobdiff_plain;f=elf%2Fneeded.c;fp=elf%2Fneeded.c;h=28bbb9b0ccfa1e5c43a83275235c9d9a35d0a2d4;hp=f4edd3dc1b353a4a825fb9b5d209305c0b71a0c7;hb=ce7874c9460a2495982499d6ae42a1f21e794b50;hpb=e5739c4df416952fbe5064436c44c172eb770aa6 diff --git a/elf/needed.c b/elf/needed.c index f4edd3d..28bbb9b 100644 --- a/elf/needed.c +++ b/elf/needed.c @@ -23,7 +23,7 @@ Elf64_Ehdr *libelf_header(void *elf) { } Elf64_Shdr *libelf_shdr(void *elf, int n) { - return 0; + return (Elf64_Shdr*)(char *)elf + n; } Elf64_Shdr *libelf_sht_strtab(void *elf) { @@ -58,7 +58,7 @@ Elf64_Shdr *libelf_section_n(void *elf, int n) { return (Elf64_Shdr *)((char *)elf + hdr->e_shoff + n * hdr->e_shentsize); } -Elf64_Shdr *libelf_section(void *elf, int type) { +Elf64_Shdr *libelf_section(void *elf, unsigned int type) { int i; Elf64_Ehdr *hdr; Elf64_Shdr *shdr; @@ -113,7 +113,7 @@ void *libelf_map(char *path, size_t *fsize) { return NULL; } /* not at least the size of the elf header? */ - if (sbuf.st_size < sizeof(Elf64_Ehdr)) { + if ((size_t)sbuf.st_size < sizeof(Elf64_Ehdr)) { close(elffd); return NULL; } @@ -177,7 +177,7 @@ int main(int ac, char **av) { exit(6); } - Elf64_Shdr *dsect; + Elf64_Shdr *dsect = 0; /* find program header table */ for (i = 0; i < hdr->e_phnum; i++) { phdr = (Elf64_Phdr *)((char *)elf + hdr->e_phoff + i * hdr->e_phentsize); @@ -185,6 +185,11 @@ int main(int ac, char **av) { dsect = (Elf64_Shdr *)((char *)elf + phdr->p_offset); } } + if (!dsect) { + /* no dsect, statically linked? */ + exit(7); + } + dyn = (Elf64_Dyn *)((char *)elf + dsect->sh_offset); if (!dyn) { exit(9);