X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Farchive64.c;h=4cccd5420f3c21a90d12741c4f3bafaca4ebc53d;hb=6077de0645ce12a9c4e99f8839a846b42a535b0a;hp=6b87ec520283b831175c19602f3c305dbdc1b3dc;hpb=4b95cf5c0c75d6efc1b2f96af72317aecca079f1;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/archive64.c b/bfd/archive64.c index 6b87ec5202..4cccd5420f 100644 --- a/bfd/archive64.c +++ b/bfd/archive64.c @@ -1,5 +1,5 @@ -/* Support for 64-bit ELF archives. - Copyright (C) 1996-2014 Free Software Foundation, Inc. +/* Support for 64-bit archives. + Copyright (C) 1996-2018 Free Software Foundation, Inc. Ian Lance Taylor, Cygnus Support Linker support added by Mark Mitchell, CodeSourcery, LLC. @@ -21,7 +21,8 @@ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -/* This file supports the 64-bit (MIPS) ELF archives. */ +/* This file supports the 64-bit archives. We use the same format as + the 64-bit (MIPS) ELF archives. */ #include "sysdep.h" #include "bfd.h" @@ -31,14 +32,10 @@ /* Irix 6 defines a 64bit archive map format, so that they can have archives more than 4 GB in size. */ -bfd_boolean bfd_elf64_archive_slurp_armap (bfd *); -bfd_boolean bfd_elf64_archive_write_armap - (bfd *, unsigned int, struct orl *, unsigned int, int); - /* Read an Irix 6 armap. */ bfd_boolean -bfd_elf64_archive_slurp_armap (bfd *abfd) +_bfd_archive_64_bit_slurp_armap (bfd *abfd) { struct artdata *ardata = bfd_ardata (abfd); char nextname[17]; @@ -46,6 +43,7 @@ bfd_elf64_archive_slurp_armap (bfd *abfd) struct areltdata *mapdata; bfd_byte int_buf[8]; char *stringbase; + char *stringend; bfd_byte *raw_armap = NULL; carsym *carsyms; bfd_size_type amt; @@ -92,11 +90,18 @@ bfd_elf64_archive_slurp_armap (bfd *abfd) ptrsize = 8 * nsymz; amt = carsym_size + stringsize + 1; + if (carsym_size < nsymz || ptrsize < nsymz || amt < nsymz) + { + bfd_set_error (bfd_error_malformed_archive); + return FALSE; + } ardata->symdefs = (struct carsym *) bfd_zalloc (abfd, amt); if (ardata->symdefs == NULL) return FALSE; carsyms = ardata->symdefs; stringbase = ((char *) ardata->symdefs) + carsym_size; + stringbase[stringsize] = 0; + stringend = stringbase + stringsize; raw_armap = (bfd_byte *) bfd_alloc (abfd, ptrsize); if (raw_armap == NULL) @@ -114,7 +119,8 @@ bfd_elf64_archive_slurp_armap (bfd *abfd) { carsyms->file_offset = bfd_getb64 (raw_armap + i * 8); carsyms->name = stringbase; - stringbase += strlen (stringbase) + 1; + if (stringbase < stringend) + stringbase += strlen (stringbase) + 1; ++carsyms; } *stringbase = '\0'; @@ -141,11 +147,11 @@ release_symdefs: linker crashes. */ bfd_boolean -bfd_elf64_archive_write_armap (bfd *arch, - unsigned int elength, - struct orl *map, - unsigned int symbol_count, - int stridx) +_bfd_archive_64_bit_write_armap (bfd *arch, + unsigned int elength, + struct orl *map, + unsigned int symbol_count, + int stridx) { unsigned int ranlibsize = (symbol_count * 8) + 8; unsigned int stringsize = stridx; @@ -171,7 +177,7 @@ bfd_elf64_archive_write_armap (bfd *arch, if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize)) return FALSE; _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld", - time (NULL)); + time (NULL)); /* This, at least, is what Intel coff sets the values to.: */ _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", 0); _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", 0);