as(1) segfault patch

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

as(1) segfault patch

Dasn-3
Hi, there.
$ uname -msr
OpenBSD 3.9 i386
$ cat > test.c << EOF && gcc -S test.c -o - | as --statistics
> main(){}
> EOF

will produce segfault.

The following patch could fix this problem.

Index: as.c
===================================================================
RCS file: /cvs/src/gnu/usr.bin/binutils/gas/as.c,v
retrieving revision 1.10
diff -u -p -r1.10 as.c
--- as.c 2 Nov 2004 20:45:22 -0000 1.10
+++ as.c 8 Sep 2006 14:15:24 -0000
@@ -847,6 +847,14 @@ dump_statistics (void)
 #endif
 }
 
+#ifndef OBJ_VMS
+static void
+close_output_file (void)
+{
+  output_file_close (out_file_name);
+}
+#endif
+
 /* The interface between the macro code and gas expression handling.  */
 
 static int
@@ -1033,6 +1041,11 @@ main (int argc, char ** argv)
   input_scrub_begin ();
   expr_begin ();
 
+#ifndef OBJ_VMS /* Does its own file handling.  */
+  /* It has to be called after dump_statistics ().  */
+  xatexit (close_output_file);
+#endif
+
   if (flag_print_statistics)
     xatexit (dump_statistics);
 
@@ -1132,12 +1145,6 @@ main (int argc, char ** argv)
   listing_print (listing_filename);
 #endif
 
-#ifndef OBJ_VMS /* Does its own file handling.  */
-#ifndef BFD_ASSEMBLER
-  if (keep_it)
-#endif
-    output_file_close (out_file_name);
-#endif
 
   if (flag_fatal_warnings && had_warnings () > 0 && had_errors () == 0)
     as_bad (_("%d warnings, treating warnings as errors"), had_warnings ());
--
Dasn