PR binutils/11983
authorNick Clifton <nickc@redhat.com>
Thu, 2 Jan 2014 12:14:37 +0000 (12:14 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 2 Jan 2014 12:14:37 +0000 (12:14 +0000)
* 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.

bfd/ChangeLog
bfd/archive.c
bfd/elfcode.h
bfd/ieee.c
bfd/mach-o.c
bfd/oasys.c
bfd/opncls.c
bfd/vms-lib.c

index d79acff62cf67ac32571dab3a013162fa14ce2ce..f35d03729ad3013ccb9396044ee8359518bdbfd3 100644 (file)
@@ -1,3 +1,20 @@
+2014-01-02  Nick Clifton  <nickc@redhat.com>
+
+       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  <ilya.tocar@intel.com>
 
        * peXXigen.c (rsrc_process_section): Use ptrdiff_t as the type for
index 32b07a718a2b9825c41885572dbd544d6803c16f..dc39751aac1cc584ad3733ee0c2a5a5f35858097 100644 (file)
@@ -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;
index e296c5ce784710bbf6178eac2d5466d15b46a7fe..032874823ba23425218c6510be65bb29da747a02 100644 (file)
@@ -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 = "<in-memory>";
+  nbfd->filename = xstrdup ("<in-memory>");
   nbfd->xvec = templ->xvec;
   bim->size = contents_size;
   bim->buffer = contents;
index b93fdeb87b4e60a6c8827cb1233a8ef14af1a7ad..e1734ec3d2815246ff379a27f285ab2199f6de1e 100644 (file)
@@ -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.  */
   {
index ffe7332a674063310989412fdd5e08aabc7cfce8..6640a6a658f8c44e3bfca319acc03d1aac7a9178 100644 (file)
@@ -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;
index ebb12e844e24ca5a7ffa0c35f7370ebf7385855f..b8e457edf0e18a1037e37d934814e8de4caca1dd 100644 (file)
@@ -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, <sac@cygnus.com>.
 
    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;
index 3f09420bf735db821a88bc6395702b6f26c7e06d..54744ced625e8457fbc20b385c73188ee1d3621f 100644 (file)
@@ -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
        <<system_call>> 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 <<NULL>> is returned then an error has occured.   Possible errors
        are <<bfd_error_no_memory>>, <<bfd_error_invalid_target>> or
        <<system_call>> 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
        <<bfd_error_invalid_target>> and <<bfd_error_system_call>>.
 
        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 <<bfd_close>>, 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 <<bfd_error_no_memory>>,
        <<bfd_error_invalid_target>> and <<bfd_error_system_call>>.
 
+       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 <<bfd_error_system_call>>, <<bfd_error_no_memory>>,
        <<bfd_error_invalid_target>>.
+
+       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 <<bfd_openw>>, but without
        opening a file. The new BFD takes the target from the target
        used by @var{templ}. The format is always set to <<bfd_object>>.
+
+       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.
index b553570d80a902f452ee9a8631e558a89c8813cf..407c1861bfe9624244316d1fa00717b1e5f8cedf 100644 (file)
@@ -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 <gingold@adacore.com>, 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;
 
This page took 0.035412 seconds and 4 git commands to generate.