1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

(process_file): Avoid possible overflow in assignment.

This commit is contained in:
Ulrich Drepper
2003-07-22 21:35:06 +00:00
parent 873a1928de
commit f00b19417d

View File

@ -23,17 +23,16 @@
development version. Besides the simplification, it has also been development version. Besides the simplification, it has also been
modified to read some other file formats. */ modified to read some other file formats. */
#include <a.out.h>
#include <elf.h> #include <elf.h>
#include <error.h> #include <error.h>
#include <link.h>
#include <libintl.h> #include <libintl.h>
#include <link.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <a.out.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/param.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <gnu/lib-names.h> #include <gnu/lib-names.h>
@ -147,12 +146,10 @@ process_file (const char *real_file_name, const char *file_name,
elf_header = (ElfW(Ehdr) *) file_contents; elf_header = (ElfW(Ehdr) *) file_contents;
if (memcmp (elf_header->e_ident, ELFMAG, SELFMAG) != 0) if (memcmp (elf_header->e_ident, ELFMAG, SELFMAG) != 0)
{ {
/* The file is neither ELF nor aout. Check if it's a linker script, /* The file is neither ELF nor aout. Check if it's a linker
like libc.so - otherwise complain. */ script, like libc.so - otherwise complain. Only search the
int len = statbuf.st_size; beginning of the file. */
/* Only search the beginning of the file. */ size_t len = MIN (statbuf.st_size, 512);
if (len > 512)
len = 512;
if (memmem (file_contents, len, "GROUP", 5) == NULL if (memmem (file_contents, len, "GROUP", 5) == NULL
&& memmem (file_contents, len, "GNU ld script", 13) == 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"), error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),