Index: libexec/rtld-elf/map_object.c =================================================================== --- libexec/rtld-elf/map_object.c +++ libexec/rtld-elf/map_object.c @@ -327,6 +327,18 @@ get_elf_header(int fd, const char *path) { Elf_Ehdr *hdr; + struct stat sb; + + /* Make sure file has enough data for the ELF header */ + if (fstat(fd, &sb) == -1) { + _rtld_error("%s: get stat error: %s", path, + rtld_strerror(errno)); + return (NULL); + } + if (sb.st_size < sizeof(Elf_Ehdr)) { + _rtld_error("%s: invalid file format", path); + return (NULL); + } hdr = mmap(NULL, PAGE_SIZE, PROT_READ, MAP_PRIVATE | MAP_PREFAULT_READ, fd, 0);