Fix a potential illegal memory access by objcopy when extracting dwo sections.
authorNick Clifton <nickc@redhat.com>
Thu, 29 Oct 2020 11:17:39 +0000 (11:17 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 29 Oct 2020 11:17:39 +0000 (11:17 +0000)
 PR 26805
 * objcopy.c (is_dwo_section): Check for missing or short section
 names.

binutils/ChangeLog
binutils/objcopy.c

index 5bd212594434e438d0c0d074c3545f6629637d07..5ccdf9b4ee7d712bf0a6faf73f03f57b3b6e964c 100644 (file)
@@ -1,3 +1,9 @@
+2020-10-29  Nick Clifton  <nickc@redhat.com>
+
+       PR 26805
+       * objcopy.c (is_dwo_section): Check for missing or short section
+       names.
+
 2020-10-26  Andreas Rammhold <andreas@rammhold.de>
 
        * README-how-to-make-a-release: Use sha256sum instead of md5sum.
index d777d740cb77032e0be23d1cfafe0b0be83eaf29..ca35df03b66f360ea750d0e23e13034b599e98bc 100644 (file)
@@ -1268,8 +1268,15 @@ group_signature (asection *group)
 static bfd_boolean
 is_dwo_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
 {
-  const char *name = bfd_section_name (sec);
-  int len = strlen (name);
+  const char *name;
+  int len;
+
+  if (sec == NULL || (name = bfd_section_name (sec)) == NULL)
+    return FALSE;
+
+  len = strlen (name);
+  if (len < 5)
+    return FALSE;
 
   return strncmp (name + len - 4, ".dwo", 4) == 0;
 }