PR27218, memory access violation in dwarf2dbg.c

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.
This commit is contained in:
Alan Modra
2021-01-21 16:46:20 +10:30
parent c78eec4424
commit 498ff0328f
2 changed files with 20 additions and 13 deletions

View File

@ -1,3 +1,10 @@
2021-01-21 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-20 Alan Modra <amodra@gmail.com> 2021-01-20 Alan Modra <amodra@gmail.com>
* testsuite/gas/ppc/power4.d: Adjust for removal of section sym. * testsuite/gas/ppc/power4.d: Adjust for removal of section sym.

View File

@ -550,8 +550,9 @@ dwarf2_gen_line_info (addressT ofs, struct dwarf2_line_info *loc)
/* Early out for as-yet incomplete location information. */ /* Early out for as-yet incomplete location information. */
if (loc->line == 0) if (loc->line == 0)
return; return;
if (loc->filenum == 0 && DWARF2_LINE_VERSION < 5) if (loc->filenum == 0)
{ {
if (dwarf_level < 5)
dwarf_level = 5; dwarf_level = 5;
if (DWARF2_LINE_VERSION < 5) if (DWARF2_LINE_VERSION < 5)
return; return;
@ -1046,10 +1047,11 @@ dwarf2_directive_filename (void)
num = get_absolute_expression (); num = get_absolute_expression ();
if ((offsetT) num < 1 && DWARF2_LINE_VERSION < 5) if ((offsetT) num < 1)
{ {
if (num == 0 && dwarf_level < 5)
dwarf_level = 5; dwarf_level = 5;
if (DWARF2_LINE_VERSION < 5) if ((offsetT) num < 0 || DWARF2_LINE_VERSION < 5)
{ {
as_bad (_("file number less than one")); as_bad (_("file number less than one"));
ignore_rest_of_line (); ignore_rest_of_line ();
@ -1149,18 +1151,16 @@ dwarf2_directive_loc (int dummy ATTRIBUTE_UNUSED)
if (filenum < 1) if (filenum < 1)
{ {
if (filenum != 0 || DWARF2_LINE_VERSION < 5) if (filenum == 0 && dwarf_level < 5)
{
dwarf_level = 5; dwarf_level = 5;
if (DWARF2_LINE_VERSION < 5) if (filenum < 0 || DWARF2_LINE_VERSION < 5)
{ {
as_bad (_("file number less than one")); as_bad (_("file number less than one"));
return; 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); as_bad (_("unassigned file number %ld"), (long) filenum);
return; return;