X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=elf%2Fsoname.c;h=06e56624eaccffbf30a8d928e09678127def7c13;hb=9daff10c7cf0cf1b983fca4a90065611ad0d3bf9;hp=aa683a53acb3bf726218dc37af3c44e51a396c1a;hpb=489ad6b12bcdfd554acd0908a1770187e76e436d;p=zpackage diff --git a/elf/soname.c b/elf/soname.c index aa683a5..06e5662 100644 --- a/elf/soname.c +++ b/elf/soname.c @@ -9,7 +9,8 @@ #include #include #include -#include + +#include "elf.h" int main(int ac, char **av) { void *elfbase; @@ -22,6 +23,11 @@ int main(int ac, char **av) { char *name, *dynname; Elf64_Dyn *dent; + if (ac < 2) { + fprintf(stderr, "usage: soname \n"); + exit(EXIT_FAILURE); + } + if (lstat(av[1], &sbuf) == -1) { exit(1); } @@ -36,9 +42,14 @@ int main(int ac, char **av) { if (fstat(elffd, &sbuf) == -1) { exit(1); } + /* not a regular file? */ if (!S_ISREG(sbuf.st_mode)) { exit(1); } + /* not at least the size of the elf header? */ + if ((size_t)sbuf.st_size < sizeof(Elf64_Ehdr)) { + exit(1); + } elfbase = mmap(0, sbuf.st_size, PROT_READ,MAP_PRIVATE, elffd, 0); if (!elfbase) {