From 625ef999a6354d9c024e886919830dfda7569f44 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sun, 26 Sep 2004 13:39:25 +0000 Subject: [BZ #151] Update. * elf/readlib.c (process_file): Before complaining about too-short file, check that it potentially be an ELF file. Also complain about empty files. [BZ #151]. --- elf/readlib.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'elf') diff --git a/elf/readlib.c b/elf/readlib.c index a1fec94589..4fbc3e5e4c 100644 --- a/elf/readlib.c +++ b/elf/readlib.c @@ -105,7 +105,15 @@ process_file (const char *real_file_name, const char *file_name, if ((size_t) statbuf.st_size < sizeof (struct exec) || (size_t) statbuf.st_size < sizeof (ElfW(Ehdr))) { - error (0, 0, _("File %s is too small, not checked."), file_name); + if (statbuf.st_size == 0) + error (0, 0, _("File %s is empty, not checked."), file_name); + else + { + char buf[SELFMAG]; + size_t n = MIN (statbuf.st_size, SELFMAG); + if (fread (buf, n, 1, file) == 1 && memcmp (buf, ELFMAG, n) == 0) + error (0, 0, _("File %s is too small, not checked."), file_name); + } fclose (file); return 1; } -- cgit 1.4.1