]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR27218, memory access violation in dwarf2dbg.c
authorAlan Modra <amodra@gmail.com>
Thu, 21 Jan 2021 06:16:20 +0000 (16:46 +1030)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 26 Jan 2021 14:24:00 +0000 (06:24 -0800)
PR 27218
* dwarf2dbg.c (dwarf2_gen_line_info): Correct setting of dwarf_level.
(dwarf2_directive_filename, dwarf2_directive_loc): Likewise, and
error for negative file numbers.

(cherry picked from commit 498ff0328fed7689f7a675d8c9f0f04bed1f1522)

gas/ChangeLog
gas/dwarf2dbg.c

index bb336ab9d5d1f617c6cc132d8e2a0384d37a8101..92ce9595d32a56711d8469fd39b0e980e84657a1 100644 (file)
@@ -1,3 +1,10 @@
+2021-01-25  Alan Modra  <amodra@gmail.com>
+
+       PR 27218
+       * dwarf2dbg.c (dwarf2_gen_line_info): Correct setting of dwarf_level.
+       (dwarf2_directive_filename, dwarf2_directive_loc): Likewise, and
+       error for negative file numbers.
+
 2021-01-25  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/27195
index 0195a82daf1b3fa361390e4fa683d2a71d998c36..419582f9aa82309a5f5e1d7629cf2845c1fa4673 100644 (file)
@@ -536,9 +536,10 @@ dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
   /* Early out for as-yet incomplete location information.  */
   if (loc->line == 0)
     return;
-  if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5)
+  if (loc->filenum == 0)
     {
-      dwarf_level = 5;
+      if (dwarf_level < 5)
+       dwarf_level = 5;
       if (DWARF2_LINE_VERSION < 5)
        return;
     }
@@ -1032,10 +1033,11 @@ dwarf2_directive_filename (void)
 
   num = get_absolute_expression ();
 
-  if ((offsetT) num < 1 && DWARF2_LINE_VERSION < 5)
+  if ((offsetT) num < 1)
     {
-      dwarf_level = 5;
-      if (DWARF2_LINE_VERSION < 5)
+      if (num == 0 && dwarf_level < 5)
+       dwarf_level = 5;
+      if ((offsetT) num < 0 || DWARF2_LINE_VERSION < 5)
        {
          as_bad (_("file number less than one"));
          ignore_rest_of_line ();
@@ -1135,18 +1137,16 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
 
   if (filenum < 1)
     {
-      if (filenum != 0 || DWARF2_LINE_VERSION < 5)
+      if (filenum == 0 && dwarf_level < 5)
+       dwarf_level = 5;
+      if (filenum < 0 || DWARF2_LINE_VERSION < 5)
        {
-         dwarf_level = 5;
-         if (DWARF2_LINE_VERSION < 5)
-           {
-             as_bad (_("file number less than one"));
-             return;
-           }
+         as_bad (_("file number less than one"));
+         return;
        }
     }
 
-  if (filenum >= (int) files_in_use || files[filenum].filename == NULL)
+  if ((valueT) filenum >= files_in_use || files[filenum].filename == NULL)
     {
       as_bad (_("unassigned file number %ld"), (long) filenum);
       return;