Re: Odd crash with strip

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Odd crash with strip

Alan Modra
On Tue, Jan 10, 2006 at 01:42:34AM -0600, R.K. wrote:
> # strip bash checkpassword cp
> BFD: checkpassword: warning: Empty loadable segment detected, is this intentional ?
>
> BFD: checkpassword: warning: Empty loadable segment detected, is this intentional ?
>
> strip: there are no sections to be copied!
> free(): invalid pointer 0x8102f78!
> Segmentation fault (core dumped)

Segfault cured like this.

        * objcopy.c (copy_object): Set isympp and osympp to NULL after free.

Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.90
diff -u -p -r1.90 objcopy.c
--- binutils/objcopy.c 15 Nov 2005 08:33:38 -0000 1.90
+++ binutils/objcopy.c 10 Jan 2006 22:10:07 -0000
@@ -1281,10 +1281,16 @@ copy_object (bfd *ibfd, bfd *obfd)
     }
 
   if (isympp)
-    free (isympp);
+    {
+      free (isympp);
+      isympp = NULL;
+    }
 
   if (osympp != isympp)
-    free (osympp);
+    {
+      free (osympp);
+      osympp = NULL;
+    }
 
   /* BFD mandates that all output sections be created and sizes set before
      any output is done.  Thus, we traverse all sections multiple times.  */

--
Alan Modra
IBM OzLabs - Linux Technology Centre

Reply | Threaded
Open this post in threaded view
|

Re: Odd crash with strip

Alan Modra
On Wed, Jan 11, 2006 at 08:43:53AM +1030, Alan Modra wrote:
> * objcopy.c (copy_object): Set isympp and osympp to NULL after free.

Reviewing my own patch before committing would have been better..
There was a good reason why the test is "osympp != isympp" rather than
"osympp != NULL", and changing isympp too early breaks this test.

        * objcopy.c (copy_object): Fix thinko.

Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.91
diff -u -p -r1.91 objcopy.c
--- binutils/objcopy.c 10 Jan 2006 22:14:18 -0000 1.91
+++ binutils/objcopy.c 10 Jan 2006 22:24:01 -0000
@@ -1281,16 +1281,13 @@ copy_object (bfd *ibfd, bfd *obfd)
     }
 
   if (isympp)
-    {
-      free (isympp);
-      isympp = NULL;
-    }
+    free (isympp);
 
   if (osympp != isympp)
-    {
-      free (osympp);
-      osympp = NULL;
-    }
+    free (osympp);
+
+  isympp = NULL;
+  osympp = NULL;
 
   /* BFD mandates that all output sections be created and sizes set before
      any output is done.  Thus, we traverse all sections multiple times.  */

--
Alan Modra
IBM OzLabs - Linux Technology Centre


_______________________________________________
bug-binutils mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/bug-binutils