From f00b19417df4f29fc3264f772c46305f60181cd6 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 22 Jul 2003 21:35:06 +0000 Subject: [PATCH] (process_file): Avoid possible overflow in assignment. --- elf/readlib.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/elf/readlib.c b/elf/readlib.c index da0f08cc0b..a1fec94589 100644 --- a/elf/readlib.c +++ b/elf/readlib.c @@ -23,17 +23,16 @@ development version. Besides the simplification, it has also been modified to read some other file formats. */ - +#include #include #include -#include #include +#include #include #include #include -#include - #include +#include #include #include @@ -147,12 +146,10 @@ process_file (const char *real_file_name, const char *file_name, elf_header = (ElfW(Ehdr) *) file_contents; if (memcmp (elf_header->e_ident, ELFMAG, SELFMAG) != 0) { - /* The file is neither ELF nor aout. Check if it's a linker script, - like libc.so - otherwise complain. */ - int len = statbuf.st_size; - /* Only search the beginning of the file. */ - if (len > 512) - len = 512; + /* The file is neither ELF nor aout. Check if it's a linker + script, like libc.so - otherwise complain. Only search the + beginning of the file. */ + size_t len = MIN (statbuf.st_size, 512); if (memmem (file_contents, len, "GROUP", 5) == NULL && memmem (file_contents, len, "GNU ld script", 13) == NULL) error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),