]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Only warn about malformed win32pstatus notes
authorJon Turney <jon.turney@dronecode.org.uk>
Fri, 17 Jul 2020 14:25:47 +0000 (15:25 +0100)
committerJon Turney <jon.turney@dronecode.org.uk>
Wed, 12 Aug 2020 14:08:30 +0000 (15:08 +0100)
bfd/ChangeLog:

2020-07-21  Jon Turney  <jon.turney@dronecode.org.uk>

* elf.c (elfcore_grok_win32pstatus): Warn on malformed
win32pstatus notes, and return TRUE so we continue rather than
stopping as if it was an error.

bfd/ChangeLog
bfd/elf.c

index fe7fdbf6a25963797b5abdde49774bddae9739ed..5539e980d6d78fdb767a3a0430f75d668acaf9e7 100644 (file)
@@ -1,3 +1,9 @@
+2020-07-21  Jon Turney  <jon.turney@dronecode.org.uk>
+
+       * elf.c (elfcore_grok_win32pstatus): Warn on malformed
+       win32pstatus notes, and return TRUE so we continue rather than
+       stopping as if it was an error.
+
 2020-07-01  Jon Turney  <jon.turney@dronecode.org.uk>
 
        * elf.c (elfcore_grok_win32pstatus): Handle NOTE_INFO_MODULE64.
index 6fad516d4628c4051e7799c599d56af437e8dfef..e8c457cd5d52e9b1f77f3ac9bcee7cf2c376938e 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -10154,21 +10154,36 @@ elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note)
 
   type = bfd_get_32 (abfd, note->descdata);
 
+  struct {
+    const char *type_name;
+    unsigned long min_size;
+  } size_check[] =
+      {
+       { "NOTE_INFO_PROCESS", 12 },
+       { "NOTE_INFO_THREAD", 12 },
+       { "NOTE_INFO_MODULE", 12 },
+       { "NOTE_INFO_MODULE64", 16 },
+      };
+
+  if (type > (sizeof(size_check)/sizeof(size_check[0])))
+      return TRUE;
+
+  if (note->descsz < size_check[type - 1].min_size)
+    {
+      _bfd_error_handler (_("%pB: warning: win32pstatus %s of size %lu bytes is too small"),
+                          abfd, size_check[type - 1].type_name, note->descsz);
+      return TRUE;
+    }
+
   switch (type)
     {
     case NOTE_INFO_PROCESS:
-      if (note->descsz < 12)
-        return FALSE;
-
       /* FIXME: need to add ->core->command.  */
       elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 4);
       elf_tdata (abfd)->core->signal = bfd_get_32 (abfd, note->descdata + 8);
       break;
 
     case NOTE_INFO_THREAD:
-      if (note->descsz < 12)
-        return FALSE;
-
       /* Make a ".reg/<tid>" section containing the Win32 API thread CONTEXT
          structure. */
       /* thread_info.tid */
@@ -10204,9 +10219,6 @@ elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note)
       /* Make a ".module/xxxxxxxx" section.  */
       if (type == NOTE_INFO_MODULE)
         {
-          if (note->descsz < 12)
-            return FALSE;
-
           /* module_info.base_address */
           base_addr = bfd_get_32 (abfd, note->descdata + 4);
           sprintf (buf, ".module/%08lx", (unsigned long) base_addr);
@@ -10215,9 +10227,6 @@ elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note)
         }
       else /* NOTE_INFO_MODULE64 */
         {
-          if (note->descsz < 16)
-            return FALSE;
-
           /* module_info.base_address */
           base_addr = bfd_get_64 (abfd, note->descdata + 4);
           sprintf (buf, ".module/%016lx", (unsigned long) base_addr);
@@ -10238,7 +10247,11 @@ elfcore_grok_win32pstatus (bfd *abfd, Elf_Internal_Note *note)
        return FALSE;
 
       if (note->descsz < 12 + name_size)
-        return FALSE;
+        {
+          _bfd_error_handler (_("%pB: win32pstatus NOTE_INFO_MODULE of size %lu is too small to contain a name of size %zu"),
+                              abfd, note->descsz, name_size);
+          return TRUE;
+        }
 
       sect->size = note->descsz;
       sect->filepos = note->descpos;