aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/ChangeLog17
-rw-r--r--bfd/archive.c2
-rw-r--r--bfd/elfcode.h7
-rw-r--r--bfd/ieee.c7
-rw-r--r--bfd/mach-o.c4
-rw-r--r--bfd/oasys.c7
-rw-r--r--bfd/opncls.c49
-rw-r--r--bfd/vms-lib.c5
8 files changed, 73 insertions, 25 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index d79acff..f35d037 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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
diff --git a/bfd/archive.c b/bfd/archive.c
index 32b07a7..dc39751 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 e296c5c..0328748 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 = "<in-memory>";
+ nbfd->filename = xstrdup ("<in-memory>");
nbfd->xvec = templ->xvec;
bim->size = contents_size;
bim->buffer = contents;
diff --git a/bfd/ieee.c b/bfd/ieee.c
index b93fdeb..e1734ec 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 ffe7332..6640a6a 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 ebb12e8..b8e457e 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, <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;
diff --git a/bfd/opncls.c b/bfd/opncls.c
index 3f09420..54744ce 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
<<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.
diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c
index b553570..407c186 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 <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;