This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
objdump /tmp problems
- To: binutils at sources dot redhat dot com
- Subject: objdump /tmp problems
- From: Philip Blundell <philb at gnu dot org>
- Date: Sat, 13 Jan 2001 19:39:37 +0000
- Cc: Solar Designer <solar at openwall dot com>
I think this patch should fix the problem with objdump mentioned in
<http://sources.redhat.com/ml/bug-gnu-utils/2001-01/msg00076.html>. Another
way to deal with the issue would be to have objdump call _new_bfd directly --
it doesn't actually want to do anything to the BFDs it creates in this
situation, other than see if a target can be successfully selected.
p.
2001-01-13 Philip Blundell <philb@gnu.org>
* objdump.c (display_target_list): Avoid unsafe use of /tmp.
(display_info_table): Likewise.
Index: objdump.c
===================================================================
RCS file: /cvs/src/src/binutils/objdump.c,v
retrieving revision 1.32
diff -u -p -u -r1.32 objdump.c
--- objdump.c 2001/01/09 20:25:31 1.32
+++ objdump.c 2001/01/13 19:37:28
@@ -2645,14 +2645,14 @@ static void
display_target_list ()
{
extern bfd_target *bfd_target_vector[];
- char *dummy_name;
int t;
- dummy_name = make_temp_file (NULL);
for (t = 0; bfd_target_vector[t]; t++)
{
+ char dummy_name[] = "/tmp/XXXXXX";
+ int fd = mkstemp(dummy_name);
bfd_target *p = bfd_target_vector[t];
- bfd *abfd = bfd_openw (dummy_name, p->name);
+ bfd *abfd = bfd_fdopenr (dummy_name, p->name, fd);
int a;
printf ("%s\n (header %s, data %s)\n", p->name,
@@ -2670,6 +2670,7 @@ display_target_list ()
if (bfd_get_error () != bfd_error_invalid_operation)
nonfatal (p->name);
bfd_close_all_done (abfd);
+ unlink (dummy_name);
continue;
}
@@ -2678,9 +2679,8 @@ display_target_list ()
printf (" %s\n",
bfd_printable_arch_mach ((enum bfd_architecture) a, 0));
bfd_close_all_done (abfd);
+ unlink (dummy_name);
}
- unlink (dummy_name);
- free (dummy_name);
}
/* Print a table showing which architectures are supported for entries
@@ -2694,7 +2694,6 @@ display_info_table (first, last)
{
extern bfd_target *bfd_target_vector[];
int t, a;
- char *dummy_name;
/* Print heading of target names. */
printf ("\n%*s", (int) LONGEST_ARCH, " ");
@@ -2702,7 +2701,6 @@ display_info_table (first, last)
printf ("%s ", bfd_target_vector[t]->name);
putchar ('\n');
- dummy_name = make_temp_file (NULL);
for (a = (int) bfd_arch_obscure + 1; a < (int) bfd_arch_last; a++)
if (strcmp (bfd_printable_arch_mach (a, 0), "UNKNOWN!") != 0)
{
@@ -2712,7 +2710,9 @@ display_info_table (first, last)
{
bfd_target *p = bfd_target_vector[t];
boolean ok = true;
- bfd *abfd = bfd_openw (dummy_name, p->name);
+ char dummy_name[] = "/tmp/XXXXXX";
+ int fd = mkstemp(dummy_name);
+ bfd *abfd = bfd_fdopenr (dummy_name, p->name, fd);
if (abfd == NULL)
{
@@ -2747,11 +2747,10 @@ display_info_table (first, last)
}
if (abfd != NULL)
bfd_close_all_done (abfd);
+ unlink (dummy_name);
}
putchar ('\n');
}
- unlink (dummy_name);
- free (dummy_name);
}
/* Print tables of all the target-architecture combinations that