From: Nick Clifton Date: Thu, 2 Jan 2014 12:14:37 +0000 (+0000) Subject: PR binutils/11983 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1be5090bca;p=binutils-gdb.git PR binutils/11983 * archive.c (_bfd_get_elt_at_filepos): Store a copy of the filename in the bfd's filename field. * elfcode.h (bfd_from_remote_memory): Likewise. * ieee.c (ieee_object_p): Likewise. * mach-o.c (bfd_mach_o_fat_member_init): Likewise. * oasys.c (oasys_openr_next_archived_file): Likewise. * vms-lib.c (_bfd_vms_lib_get_module): Likewise. * opncls.c (bfd_fopen): Likewise. (bfd_openstreamr): Likewise. (bfd_openr_iovec): Likewise. (bfd_openw): Likewise. (bfd_create): Likewise. (_bfd_delete_bfd): Free filename. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index d79acff62cf..f35d03729ad 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,20 @@ +2014-01-02 Nick Clifton + + PR binutils/11983 + * archive.c (_bfd_get_elt_at_filepos): Store a copy of the + filename in the bfd's filename field. + * elfcode.h (bfd_from_remote_memory): Likewise. + * ieee.c (ieee_object_p): Likewise. + * mach-o.c (bfd_mach_o_fat_member_init): Likewise. + * oasys.c (oasys_openr_next_archived_file): Likewise. + * vms-lib.c (_bfd_vms_lib_get_module): Likewise. + * opncls.c (bfd_fopen): Likewise. + (bfd_openstreamr): Likewise. + (bfd_openr_iovec): Likewise. + (bfd_openw): Likewise. + (bfd_create): Likewise. + (_bfd_delete_bfd): Free filename. + 2013-12-30 Ilya Tocar * peXXigen.c (rsrc_process_section): Use ptrdiff_t as the type for diff --git a/bfd/archive.c b/bfd/archive.c index 32b07a718a2..dc39751aac1 100644 --- a/bfd/archive.c +++ b/bfd/archive.c @@ -705,7 +705,7 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos) else { n_nfd->origin = n_nfd->proxy_origin; - n_nfd->filename = filename; + n_nfd->filename = xstrdup (filename); } n_nfd->arelt_data = new_areldata; diff --git a/bfd/elfcode.h b/bfd/elfcode.h index e296c5ce784..032874823ba 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -1,7 +1,5 @@ /* ELF executable support for BFD. - Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, - 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 - Free Software Foundation, Inc. + Copyright 1991-2013 Free Software Foundation, Inc. Written by Fred Fish @ Cygnus Support, from information published in "UNIX System V Release 4, Programmers Guide: ANSI C and @@ -73,6 +71,7 @@ #include "bfdlink.h" #include "libbfd.h" #include "elf-bfd.h" +#include "libiberty.h" /* Renaming structures, typedefs, macros and functions to be size-specific. */ #define Elf_External_Ehdr NAME(Elf,External_Ehdr) @@ -1804,7 +1803,7 @@ NAME(_bfd_elf,bfd_from_remote_memory) bfd_set_error (bfd_error_no_memory); return NULL; } - nbfd->filename = ""; + nbfd->filename = xstrdup (""); nbfd->xvec = templ->xvec; bim->size = contents_size; bim->buffer = contents; diff --git a/bfd/ieee.c b/bfd/ieee.c index b93fdeb87b4..e1734ec3d28 100644 --- a/bfd/ieee.c +++ b/bfd/ieee.c @@ -1,7 +1,5 @@ /* BFD back-end for ieee-695 objects. - Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, - 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011 - Free Software Foundation, Inc. + Copyright 1990-2013 Free Software Foundation, Inc. Written by Steve Chamberlain of Cygnus Support. @@ -35,6 +33,7 @@ #include "ieee.h" #include "libieee.h" #include "safe-ctype.h" +#include "libiberty.h" struct output_buffer_struct { @@ -1824,7 +1823,7 @@ ieee_object_p (bfd *abfd) goto got_wrong_format; ieee->mb.module_name = read_id (&(ieee->h)); if (abfd->filename == (const char *) NULL) - abfd->filename = ieee->mb.module_name; + abfd->filename = xstrdup (ieee->mb.module_name); /* Determine the architecture and machine type of the object file. */ { diff --git a/bfd/mach-o.c b/bfd/mach-o.c index ffe7332a674..6640a6a658f 100644 --- a/bfd/mach-o.c +++ b/bfd/mach-o.c @@ -4353,13 +4353,13 @@ bfd_mach_o_fat_member_init (bfd *abfd, if (ap) { /* Use the architecture name if known. */ - abfd->filename = ap->printable_name; + abfd->filename = xstrdup (ap->printable_name); } else { /* Forge a uniq id. */ const size_t namelen = 2 + 8 + 1 + 2 + 8 + 1; - char *name = bfd_alloc (abfd, namelen); + char *name = xmalloc (namelen); snprintf (name, namelen, "0x%lx-0x%lx", entry->cputype, entry->cpusubtype); abfd->filename = name; diff --git a/bfd/oasys.c b/bfd/oasys.c index ebb12e844e2..b8e457edf0e 100644 --- a/bfd/oasys.c +++ b/bfd/oasys.c @@ -1,7 +1,5 @@ /* BFD back-end for oasys objects. - Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2001, - 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011 - Free Software Foundation, Inc. + Copyright 1990-2013 Free Software Foundation, Inc. Written by Steve Chamberlain of Cygnus Support, . This file is part of BFD, the Binary File Descriptor library. @@ -28,6 +26,7 @@ #include "libbfd.h" #include "oasys.h" #include "liboasys.h" +#include "libiberty.h" /* Read in all the section data and relocation stuff too. */ @@ -1118,7 +1117,7 @@ oasys_openr_next_archived_file (bfd *arch, bfd *prev) { p->abfd = _bfd_create_empty_archive_element_shell (arch); p->abfd->origin = p->pos; - p->abfd->filename = p->name; + p->abfd->filename = xstrdup (p->name); /* Fixup a pointer to this element for the member. */ p->abfd->arelt_data = (void *) p; diff --git a/bfd/opncls.c b/bfd/opncls.c index 3f09420bf73..54744ced625 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -123,6 +123,8 @@ _bfd_delete_bfd (bfd *abfd) objalloc_free ((struct objalloc *) abfd->memory); } + if (abfd->filename) + free ((char *) abfd->filename); free (abfd->arelt_data); free (abfd); } @@ -181,6 +183,9 @@ DESCRIPTION <> error. On error, @var{fd} is always closed. + + A copy of the @var{filename} argument is stored in the newly created + BFD. It can be accessed via the bfd_get_filename() macro. */ bfd * @@ -220,7 +225,10 @@ bfd_fopen (const char *filename, const char *target, const char *mode, int fd) } /* OK, put everything where it belongs. */ - nbfd->filename = filename; + + /* PR 11983: Do not cache the original filename, but + rather make a copy - the original might go away. */ + nbfd->filename = xstrdup (filename); /* Figure out whether the user is opening the file for reading, writing, or both, by looking at the MODE argument. */ @@ -266,6 +274,9 @@ DESCRIPTION If <> is returned then an error has occured. Possible errors are <>, <> or <> error. + + A copy of the @var{filename} argument is stored in the newly created + BFD. It can be accessed via the bfd_get_filename() macro. */ bfd * @@ -307,6 +318,9 @@ DESCRIPTION <> and <>. On error, @var{fd} is closed. + + A copy of the @var{filename} argument is stored in the newly created + BFD. It can be accessed via the bfd_get_filename() macro. */ bfd * @@ -349,12 +363,15 @@ FUNCTION bfd_openstreamr SYNOPSIS - bfd *bfd_openstreamr (const char *, const char *, void *); + bfd *bfd_openstreamr (const char * filename, const char * target, void * stream); DESCRIPTION Open a BFD for read access on an existing stdio stream. When the BFD is passed to <>, the stream will be closed. + + A copy of the @var{filename} argument is stored in the newly created + BFD. It can be accessed via the bfd_get_filename() macro. */ bfd * @@ -376,7 +393,9 @@ bfd_openstreamr (const char *filename, const char *target, void *streamarg) } nbfd->iostream = stream; - nbfd->filename = filename; + /* PR 11983: Do not cache the original filename, but + rather make a copy - the original might go away. */ + nbfd->filename = xstrdup (filename); nbfd->direction = read_direction; if (! bfd_cache_init (nbfd)) @@ -441,6 +460,8 @@ DESCRIPTION occurred. Possible errors are <>, <> and <>. + A copy of the @var{filename} argument is stored in the newly created + BFD. It can be accessed via the bfd_get_filename() macro. */ struct opncls @@ -566,7 +587,9 @@ bfd_openr_iovec (const char *filename, const char *target, return NULL; } - nbfd->filename = filename; + /* PR 11983: Do not cache the original filename, but + rather make a copy - the original might go away. */ + nbfd->filename = xstrdup (filename); nbfd->direction = read_direction; /* `open_p (...)' would get expanded by an the open(2) syscall macro. */ @@ -607,6 +630,9 @@ DESCRIPTION Possible errors are <>, <>, <>. + + A copy of the @var{filename} argument is stored in the newly created + BFD. It can be accessed via the bfd_get_filename() macro. */ bfd * @@ -628,7 +654,9 @@ bfd_openw (const char *filename, const char *target) return NULL; } - nbfd->filename = filename; + /* PR 11983: Do not cache the original filename, but + rather make a copy - the original might go away. */ + nbfd->filename = xstrdup (filename); nbfd->direction = write_direction; if (bfd_open_file (nbfd) == NULL) @@ -765,6 +793,9 @@ DESCRIPTION Create a new BFD in the manner of <>, but without opening a file. The new BFD takes the target from the target used by @var{templ}. The format is always set to <>. + + A copy of the @var{filename} argument is stored in the newly created + BFD. It can be accessed via the bfd_get_filename() macro. */ bfd * @@ -775,7 +806,9 @@ bfd_create (const char *filename, bfd *templ) nbfd = _bfd_new_bfd (); if (nbfd == NULL) return NULL; - nbfd->filename = filename; + /* PR 11983: Do not cache the original filename, but + rather make a copy - the original might go away. */ + nbfd->filename = xstrdup (filename); if (templ) nbfd->xvec = templ->xvec; nbfd->direction = no_direction; @@ -1132,8 +1165,8 @@ SYNOPSIS char *bfd_get_debug_link_info (bfd *abfd, unsigned long *crc32_out); DESCRIPTION - fetch the filename and CRC32 value for any separate debuginfo - associated with @var{abfd}. Return NULL if no such info found, + Fetch the filename and CRC32 value for any separate debuginfo + associated with @var{abfd}. Return NULL if no such info found, otherwise return filename and update @var{crc32_out}. The returned filename is allocated with @code{malloc}; freeing it is the responsibility of the caller. diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c index b553570d80a..407c1861bfe 100644 --- a/bfd/vms-lib.c +++ b/bfd/vms-lib.c @@ -1,6 +1,6 @@ /* BFD back-end for VMS archive files. - Copyright 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright 2010-2013 Free Software Foundation, Inc. Written by Tristan Gingold , AdaCore. This file is part of BFD, the Binary File Descriptor library. @@ -25,6 +25,7 @@ #include "libbfd.h" #include "safe-ctype.h" #include "bfdver.h" +#include "libiberty.h" #include "vms.h" #include "vms/lbr.h" #include "vms/dcx.h" @@ -1376,7 +1377,7 @@ _bfd_vms_lib_get_module (bfd *abfd, unsigned int modidx) default: break; } - res->filename = name; + res->filename = xstrdup (name); tdata->cache[modidx] = res;