]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix stack buffer overflows when parsing corrupt ihex files.
authorYuriy M. Kaminskiy <yumkam@gmail.com>
Tue, 4 Aug 2015 15:51:53 +0000 (16:51 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 4 Aug 2015 15:51:53 +0000 (16:51 +0100)
PR binutils/18750
* ihex.c (ihex_scan): Fixes incorrect escape sequence in error message
and stack overflow when char is signed and \200-\376 was in place of hex
digit; also fixes \377 was handled as EOF instead of "incorrect character".
(ihex_read_section): Changed for consistency.
(ihex_bad_byte): Prevent (now impossible to trigger) stack
overflow and incorrect escape sequence handling.
* srec.c (srec_bad_byte): Likewise.

* readelf.c (process_mips_specific): Fix incorrect escape
sequence handling.

bfd/ChangeLog
bfd/ihex.c
bfd/srec.c
binutils/ChangeLog
binutils/readelf.c

index 986299d7796aaea8699af3326445bb63250a058b..a8b3646cfe4d486f8247b5d7a684ee603246ddd0 100644 (file)
@@ -1,3 +1,15 @@
+2015-08-04  Yuriy M. Kaminskiy"  <yumkam@gmail.com>
+           Tyler Hicks  <tyhicks@canonical.com>
+
+       PR binutils/18750
+       * ihex.c (ihex_scan): Fixes incorrect escape sequence in error message
+       and stack overflow when char is signed and \200-\376 was in place of hex
+       digit; also fixes \377 was handled as EOF instead of "incorrect character".
+       (ihex_read_section): Changed for consistency.
+       (ihex_bad_byte): Prevent (now impossible to trigger) stack
+       overflow and incorrect escape sequence handling.
+       * srec.c (srec_bad_byte): Likewise.
+
 2015-08-03  Hans-Peter Nilsson  <hp@axis.com>
 
        * elf32-cris.c (cris_elf_relocate_section)
index 8e663726eee89ed01b21b8df801a5180a3472021..38112f6e0d097051ca75678f9b42336c4eac5c01 100644 (file)
@@ -219,7 +219,7 @@ ihex_bad_byte (bfd *abfd, unsigned int lineno, int c, bfd_boolean error)
       char buf[10];
 
       if (! ISPRINT (c))
-       sprintf (buf, "\\%03o", (unsigned int) c);
+       sprintf (buf, "\\%03o", (unsigned int) c & 0xff);
       else
        {
          buf[0] = c;
@@ -276,7 +276,7 @@ ihex_scan (bfd *abfd)
       else
        {
          file_ptr pos;
-         char hdr[8];
+         unsigned char hdr[8];
          unsigned int i;
          unsigned int len;
          bfd_vma addr;
@@ -553,7 +553,7 @@ ihex_read_section (bfd *abfd, asection *section, bfd_byte *contents)
   error = FALSE;
   while ((c = ihex_get_byte (abfd, &error)) != EOF)
     {
-      char hdr[8];
+      unsigned char hdr[8];
       unsigned int len;
       unsigned int type;
       unsigned int i;
index 24573cff61b4c9594527d62a8a16c63dc0e10dfd..96b6a2f084f758c23fd5f36d648698cb4a11ce96 100644 (file)
@@ -249,7 +249,7 @@ srec_bad_byte (bfd *abfd,
       char buf[40];
 
       if (! ISPRINT (c))
-       sprintf (buf, "\\%03o", (unsigned int) c);
+       sprintf (buf, "\\%03o", (unsigned int) c & 0xff);
       else
        {
          buf[0] = c;
index 75f5d21251382191baa7f762227bb5e38bfe18a6..33c5e7d794cddb8616e7c1badb7fcd0ac279e397 100644 (file)
@@ -1,3 +1,14 @@
+2015-08-04  Yuriy M. Kaminskiy"  <yumkam@gmail.com>
+           Tyler Hicks  <tyhicks@canonical.com>
+
+       PR binutils/18750
+       * readelf.c (process_mips_specific): Fix incorrect escape
+       sequence handling.
+
+2015-08-04  Nick Clifton  <nickc@redhat.com>
+
+       * ar.c (extract_file): Free cbuf if the path is invalid.
+
 2015-07-27  H.J. Lu  <hongjiu.lu@intel.com>
 
        * configure: Regenerated.
index a9b9f2dbbd2023ab6d58473a95643597503cc705..6298f1e29d8a298010078a7d1b23a9a0a5fa1519 100644 (file)
@@ -14467,7 +14467,7 @@ process_mips_specific (FILE * file)
              len = sizeof (* eopt);
              while (len < option->size)
                {
-                 char datum = * ((char *) eopt + offset + len);
+                 unsigned char datum = * ((unsigned char *) eopt + offset + len);
 
                  if (ISPRINT (datum))
                    printf ("%c", datum);