This is the mail archive of the
binutils@sourceware.cygnus.com
mailing list for the binutils project.
Patch to eliminate garbage in DJGPP execs
- To: binutils at sourceware dot cygnus dot com
- Subject: Patch to eliminate garbage in DJGPP execs
- From: "Mark E." <snowball3 at bigfoot dot com>
- Date: Fri, 30 Jun 2000 21:07:50 -0400
Hello once again,
First, thanks to DJ and Nick for handling my barrage of patches over the last several
days. This one should be the last for a little while barring any last minute
developments.
In DJGPP executables, the area between the end of the section headers and the start of
the first section's data (typically the .text section's) contains garbage. This garbage
is what was already there when the space was allocated on the disk. It's there because
the operating system doesn't blank the space out when seeking past EOF, like the object
file output routine does. This presents an obvious security risk if you distribute this
executable. The patch below blanks out this area for DJGPP-specific targets to
eliminate this risk.
bfd/Changelog:
2000-06-30 Mark Elbrecht <snowball3@bigfoot.com>
* coff-go32.c (coff_write_object_scnhdrs_post): New function.
* coff-stgo32.c (coff_write_object_scnhdrs_post): Likewise.
* coff-go32.c (COFF_WRITE_OBJECT_SCNHDRS_POST): Define.
* coffcode.h (coff_write_object_contents): Use it if defined.
* coff-stgo32.c (COFF_WRITE_OBJECT_SCNHDRS_POST): Define.
* coff-go32.c: Include bfd.h.
Index: src/bfd/coff-go32.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-go32.c,v
retrieving revision 1.5
diff -c -p -r1.5 coff-go32.c
*** coff-go32.c 2000/05/03 04:25:33 1.5
--- coff-go32.c 2000/07/01 00:37:52
*************** Foundation, Inc., 59 Temple Place - Suit
*** 38,41 ****
--- 38,75 ----
{ COFF_SECTION_NAME_PARTIAL_MATCH (".gnu.linkonce.r"), \
COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }
+ #include "bfd.h"
+
+ static void
+ coff_write_object_scnhdrs_post PARAMS ((bfd *));
+
+ #define COFF_WRITE_OBJECT_SCNHDRS_POST coff_write_object_scnhdrs_post
+
#include "coff-i386.c"
+
+ /* Fill the gap between the end of the section headers and the start
+ start of the first section's contents if creating an executable.
+ This is needed for certain operating systems that do not blank the
+ space created by seeking a file past EOF. */
+
+ static void
+ coff_write_object_scnhdrs_post (abfd)
+ bfd * abfd;
+ {
+ if (abfd->flags & EXEC_P)
+ {
+ long curpos = bfd_tell (abfd);
+ long filepos = abfd->sections->filepos;
+ long fill_size = filepos - curpos;
+
+ if (fill_size > 0)
+ {
+ bfd_byte *b = bfd_zmalloc (fill_size);
+ if (b)
+ {
+ bfd_write ((PTR)b, 1, fill_size, abfd);
+ free (b);
+ }
+ }
+ }
+ }
Index: src/bfd/coff-stgo32.c
===================================================================
RCS file: /cvs/src/src/bfd/coff-stgo32.c,v
retrieving revision 1.6
diff -c -p -r1.6 coff-stgo32.c
*** coff-stgo32.c 2000/05/03 04:25:33 1.6
--- coff-stgo32.c 2000/07/01 00:38:01
*************** static boolean
*** 104,109 ****
--- 104,114 ----
#define coff_bfd_copy_private_bfd_data go32_stubbed_coff_bfd_copy_private_bfd_data
+ static void
+ coff_write_object_scnhdrs_post PARAMS ((bfd *));
+
+ #define COFF_WRITE_OBJECT_SCNHDRS_POST coff_write_object_scnhdrs_post
+
#include "coff-i386.c"
/* I hold in the usrdata the stub */
*************** go32_stubbed_coff_bfd_copy_private_bfd_d
*** 419,422 ****
--- 424,454 ----
memcpy (bfd_coff_go32stub (obfd), bfd_coff_go32stub (ibfd), STUBSIZE);
return true;
+ }
+
+ /* Fill the gap between the end of the section headers and the start
+ start of the first section's contents if creating an executable.
+ This is needed for those operating systems that do not blank the
+ space created by seeking a file past EOF. */
+
+ static void
+ coff_write_object_scnhdrs_post (abfd)
+ bfd * abfd;
+ {
+ if (abfd->flags & EXEC_P)
+ {
+ long curpos = bfd_tell (abfd);
+ long filepos = abfd->sections->filepos;
+ long fill_size = filepos - curpos;
+
+ if (fill_size > 0)
+ {
+ bfd_byte *b = bfd_zmalloc (fill_size);
+ if (b)
+ {
+ bfd_write ((PTR)b, 1, fill_size, abfd);
+ free (b);
+ }
+ }
+ }
}
Index: src/bfd/coffcode.h
===================================================================
RCS file: /cvs/src/src/bfd/coffcode.h,v
retrieving revision 1.44
diff -c -p -r1.44 coffcode.h
*** coffcode.h 2000/06/19 01:22:37 1.44
--- coffcode.h 2000/07/01 00:43:04
*************** coff_write_object_contents (abfd)
*** 3523,3528 ****
--- 3523,3534 ----
}
#endif
+ /* Perform target dependant code when neccessary
+ after writing out the section headers. */
+ #ifdef COFF_WRITE_OBJECT_SCNHDRS_POST
+ COFF_WRITE_OBJECT_SCNHDRS_POST (abfd);
+ #endif
+
/* OK, now set up the filehdr... */
/* Don't include the internal abs section in the section count */