This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch][gold] - Check output_section ptr


The attached patch adds a NULL check for the return of get_output_section
in find_memory_region fixing a crash.

Test case:

$ cat t.lnk
OUTPUT_FORMAT(binary)
ENTRY(_start)

MEMORY
{
   ram      :    ORIGIN = 0x00007c00,  LENGTH = 0x200
}

SECTIONS
{
   .text : {*(.text)
           }> ram
}
$ touch empty
$ ./ld-new empty -Tt.lnk
./ld-new: error: empty: file is empty
Segmentation fault

2010-11-02 Ryan Mansfield <rmansfield@qnx.com>

        * script-sections.cc (Script_sections::find_memory_region): Check
        for a NULL output section pointer.

Regards,

Ryan Mansfield
Index: gold/script-sections.cc
===================================================================
RCS file: /cvs/src/src/gold/script-sections.cc,v
retrieving revision 1.45
diff -u -r1.45 script-sections.cc
--- gold/script-sections.cc	12 Oct 2010 19:21:41 -0000	1.45
+++ gold/script-sections.cc	3 Nov 2010 13:05:05 -0000
@@ -2237,7 +2237,7 @@
       // are compatible with the section.  If we do not find an
       // explicit region assignment, then we will return this region.
       Output_section* out_sec = section->get_output_section();
-      if (first_match == NULL
+      if (first_match == NULL && out_sec != NULL
 	  && (*mr)->attributes_compatible(out_sec->flags(),
 					  out_sec->type()))
 	first_match = *mr;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]