Hi Stefan,

Stefan Sperling wrote:
Resending in one piece because the archive munged my message.
Sorry for the noise.

Looks good, applied to CVS.

Regards
Greg



On Wed, Jul 25, 2007 at 11:51:42PM +0200, Stefan Sperling wrote:

Hello,

elf2flt crashes on Linux/amd64:

(gdb)  run  -a -o links -p links.gdb links.gdb
Starting program: /home/stsp/dslinux/toolchain/prefix/bin/arm-linux-elf-elf2flt 
-a -o links -p links.gdb links.gdb
Program received signal SIGSEGV, Segmentation fault. _bfd_elf_canonicalize_reloc (abfd=<value optimized out>, section=0x5f6900, relptr=0xffffffffa6360010, symbols=<value optimized out>)
    at /home/stsp/dslinux/toolchain/src/binutils-2.17/bfd/elf.c:6367
6367        *relptr++ = tblptr++;
(gdb) bt
#0 _bfd_elf_canonicalize_reloc (abfd=<value optimized out>, section=0x5f6900, relptr=0xffffffffa6360010, symbols=<value optimized out>)
    at /home/stsp/dslinux/toolchain/src/binutils-2.17/bfd/elf.c:6367
#1 0x00000000004006dd in output_relocs (abs_bfd=0x5f5570, symbols=0x2b30a5e99010, number_of_symbols=16585, n_relocs=0x7fff04c0fe58, text=0x2b30a6102010 "", text_len=<value optimized out>, text_vma=0, data=0x2b30a627b010 "", data_len=934480, data_vma=1541824, rel_bfd=0x5f4400)
    at /home/stsp/dslinux/toolchain/src/elf2flt-20051225/elf2flt.c:587
#2 0x0000000000401180 in main (argc=<value optimized out>, argv=<value optimized out>)
    at /home/stsp/dslinux/toolchain/src/elf2flt-20051225/elf2flt.c:1949

The problem seems to be that the one and only call to xmalloc()
in elf2flt.c does not return a valid pointer for some reason.

I'm wondering why xmalloc() is used exactly once in elf2flt.c.
All other heap allocations in elf2flt are done with plain malloc().

The attached patch fixes the segfault by replacing the call to xmalloc()
with a call to malloc(). It also makes elf2flt check for return
values of malloc() calls, providing the equivalent behaviour of
using xmalloc().


Index: elf2flt.c
===================================================================
RCS file: /var/cvs/elf2flt/elf2flt.c,v
retrieving revision 1.46
diff -u -r1.46 elf2flt.c
--- elf2flt.c   14 Nov 2006 22:20:08 -0000      1.46
+++ elf2flt.c   24 Jul 2007 10:43:34 -0000
@@ -236,6 +236,10 @@
     return NULL;
symbol_table = (asymbol **) malloc (storage_needed);
+  if (symbol_table == NULL) {
+      perror("malloc");
+      exit(1);
+  }
number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table); @@ -492,7 +496,12 @@
        }
symb = get_symbols(rel_bfd, &nsymb);
-       relpp = (arelent **) xmalloc(relsize);
+       relpp = (arelent **) malloc(relsize);
+       if (relpp == NULL) {
+         perror("malloc");
+         exit(1);
+       }
+
        relcount = bfd_canonicalize_reloc(rel_bfd, r, relpp, symb);
        if (relcount <= 0) {
                if (verbose)
@@ -1975,6 +1984,10 @@
   }
text = malloc(text_len);
+  if (text == NULL) {
+      perror("malloc");
+      exit(1);
+  }
if (verbose)
     printf("TEXT -> vma=0x%x len=0x%x\n", text_vma, text_len);
@@ -1995,6 +2008,10 @@
     exit (2);
   }
   data = malloc(data_len);
+  if (data == NULL) {
+      perror("malloc");
+      exit(1);
+  }
if (verbose)
     printf("DATA -> vma=0x%x len=0x%x\n", data_vma, data_len);
@@ -2079,6 +2096,10 @@
if (!ofile) {
     ofile = malloc(strlen(fname) + 5 + 1); /* 5 to add suffix */
+    if (ofile == NULL) {
+       perror("malloc");
+       exit(1);
+    }
     strcpy(ofile, fname);
     strcat(ofile, ".bflt");
   }





--
------------------------------------------------------------------------
Greg Ungerer  --  Chief Software Dude       EMAIL:     [EMAIL PROTECTED]
Secure Computing Corporation                PHONE:       +61 7 3435 2888
825 Stanley St,                             FAX:         +61 7 3891 3630
Woolloongabba, QLD, 4102, Australia         WEB: http://www.SnapGear.com
_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev

Reply via email to