* strip/objcopy segfault with archives
@ 2011-05-06 12:35 Alan Modra
0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2011-05-06 12:35 UTC (permalink / raw)
To: binutils
A recently added testcase to PR12632 exposed a bug in strip/objcopy, a
missing check on the return status from bfd_openw, which led to a
segfault. This patch fixes that and shares code common to both the
copy_object and copy_unknown_object cases, in the process getting rid
of a goto.
Applying mainline, when/if sourceware cvs will talk to me.
* objcopy.c (copy_archive): Check bfd_openw result in unknown object
case. Rewrite without goto.
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.151
diff -u -p -r1.151 objcopy.c
--- binutils/objcopy.c 4 Apr 2011 01:35:59 -0000 1.151
+++ binutils/objcopy.c 6 May 2011 10:15:06 -0000
@@ -2024,6 +2024,7 @@ copy_archive (bfd *ibfd, bfd *obfd, cons
struct stat buf;
int stat_status = 0;
bfd_boolean del = TRUE;
+ bfd_boolean ok_object;
/* Create an output file for this member. */
output_name = concat (dir, "/",
@@ -2061,44 +2062,42 @@ copy_archive (bfd *ibfd, bfd *obfd, cons
l->obfd = NULL;
list = l;
- if (bfd_check_format (this_element, bfd_object))
+ ok_object = bfd_check_format (this_element, bfd_object);
+ if (!ok_object)
+ bfd_nonfatal_message (NULL, this_element, NULL,
+ _("Unable to recognise the format of file"));
+
+ /* PR binutils/3110: Cope with archives
+ containing multiple target types. */
+ if (force_output_target || !ok_object)
+ output_bfd = bfd_openw (output_name, output_target);
+ else
+ output_bfd = bfd_openw (output_name, bfd_get_target (this_element));
+
+ if (output_bfd == NULL)
{
- /* PR binutils/3110: Cope with archives
- containing multiple target types. */
- if (force_output_target)
- output_bfd = bfd_openw (output_name, output_target);
- else
- output_bfd = bfd_openw (output_name, bfd_get_target (this_element));
+ bfd_nonfatal_message (output_name, NULL, NULL, NULL);
+ status = 1;
+ return;
+ }
+
+ if (ok_object)
+ {
+ del = !copy_object (this_element, output_bfd, input_arch);
- if (output_bfd == NULL)
+ if (del && bfd_get_arch (this_element) == bfd_arch_unknown)
+ /* Try again as an unknown object file. */
+ ok_object = FALSE;
+ else if (!bfd_close (output_bfd))
{
bfd_nonfatal_message (output_name, NULL, NULL, NULL);
+ /* Error in new object file. Don't change archive. */
status = 1;
- return;
}
-
- del = ! copy_object (this_element, output_bfd, input_arch);
-
- if (! del
- || bfd_get_arch (this_element) != bfd_arch_unknown)
- {
- if (!bfd_close (output_bfd))
- {
- bfd_nonfatal_message (output_name, NULL, NULL, NULL);
- /* Error in new object file. Don't change archive. */
- status = 1;
- }
- }
- else
- goto copy_unknown_element;
}
- else
- {
- bfd_nonfatal_message (NULL, this_element, NULL,
- _("Unable to recognise the format of file"));
- output_bfd = bfd_openw (output_name, output_target);
-copy_unknown_element:
+ if (!ok_object)
+ {
del = !copy_unknown_object (this_element, output_bfd);
if (!bfd_close_all_done (output_bfd))
{
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-05-06 12:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-06 12:35 strip/objcopy segfault with archives Alan Modra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).