public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [patch bfd]: Prevent possible buffer overflow on pdata-section sorting
@ 2011-04-06 16:50 Kai Tietz
  2011-04-06 21:55 ` h.becker
  2011-04-07  1:09 ` Alan Modra
  0 siblings, 2 replies; 11+ messages in thread
From: Kai Tietz @ 2011-04-06 16:50 UTC (permalink / raw)
  To: Binutils; +Cc: Nick Clifton

[-- Attachment #1: Type: text/plain, Size: 455 bytes --]

Hello,

this issue was reported by H. Becker to me.  He found that the code in
peXXigen.c about pdata-section sorting might cause a buffer-overrun
for large pdata-data.  By working in private allocated buffer -
instead of using the pfinfo->contents - avoids this.

ChangeLog

2011-04-06  Kai Tietz

        * peXXigen.c (_bfd_XXi_final_link_postscripte): Sort pdata in temporary
        buffer.

Tested for x86_64-w64-mingw32. Ok for apply?

Regards,
Kai

[-- Attachment #2: pdata_x64_sort.txt --]
[-- Type: text/plain, Size: 1074 bytes --]

Index: src/bfd/peXXigen.c
===================================================================
--- src.orig/bfd/peXXigen.c	2010-12-21 19:33:07.000000000 +0100
+++ src/bfd/peXXigen.c	2011-04-06 18:19:45.945394800 +0200
@@ -2459,14 +2459,22 @@ _bfd_XXi_final_link_postscript (bfd * ab
     if (sec)
       {
 	bfd_size_type x = sec->rawsize ? sec->rawsize : sec->size;
+	bfd_byte *tmp_data = NULL;
 
-	if (x && bfd_get_section_contents (abfd, sec, pfinfo->contents, 0, x))
+	if (x)
+	  tmp_data = bfd_malloc (x);
+
+	if (tmp_data != NULL)
 	  {
-	    qsort (pfinfo->contents,
-	    	   (size_t) ((sec->size <x ? sec->size : x) / 12),
-	    	   12, sort_x64_pdata);
-	    bfd_set_section_contents (pfinfo->output_bfd, sec,
-	    			      pfinfo->contents, 0, x);
+	    if (bfd_get_section_contents (abfd, sec, tmp_data, 0, x))
+	      {
+		qsort (tmp_data,
+		       (size_t) ((sec->size <x ? sec->size : x) / 12),
+		       12, sort_x64_pdata);
+		bfd_set_section_contents (pfinfo->output_bfd, sec,
+					  tmp_data, 0, x);
+	      }
+	    free (tmp_data);
 	  }
       }
   }

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-04-11  4:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-06 16:50 [patch bfd]: Prevent possible buffer overflow on pdata-section sorting Kai Tietz
2011-04-06 21:55 ` h.becker
2011-04-07  1:09 ` Alan Modra
2011-04-07  5:55   ` Kai Tietz
2011-04-07  6:15     ` Kai Tietz
2011-04-07  8:52       ` Alan Modra
2011-04-07 14:31         ` Kai Tietz
2011-04-09  4:40           ` Alan Modra
2011-04-09  9:50             ` Kai Tietz
     [not found]               ` <20110409131155.GH19002@bubble.grove.modra.org>
     [not found]                 ` <BANLkTikediRDiabar9P0k526O4Pyy_qWSQ@mail.gmail.com>
     [not found]                   ` <20110409140103.GI19002@bubble.grove.modra.org>
2011-04-09 16:07                     ` Kai Tietz
2011-04-11  4:08         ` rawsize and output sections Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).