display_debug_macinfo

The existing code went to the bother of using strnlen for scanning but
went wild when printing, and possibly incremented curr past end.

	* dwarf.c (display_debug_macinfo): Print strings that might not
	be zero terminated with %*s.  Don't bump curr if unterminated.
This commit is contained in:
Alan Modra
2021-05-15 15:01:51 +09:30
parent 35b2c89ec8
commit c03df92247
2 changed files with 20 additions and 9 deletions

View File

@ -1,3 +1,8 @@
2021-05-15 Alan Modra <amodra@gmail.com>
* dwarf.c (display_debug_macinfo): Print strings that might not
be zero terminated with %*s. Don't bump curr if unterminated.
2021-05-15 Alan Modra <amodra@gmail.com> 2021-05-15 Alan Modra <amodra@gmail.com>
* dwarf.c (display_debug_pubnames_worker): Delete initial_length_size. * dwarf.c (display_debug_pubnames_worker): Delete initial_length_size.

View File

@ -5780,17 +5780,21 @@ display_debug_macinfo (struct dwarf_section *section,
case DW_MACINFO_define: case DW_MACINFO_define:
READ_ULEB (lineno, curr, end); READ_ULEB (lineno, curr, end);
string = curr; string = curr;
curr += strnlen ((char *) string, end - string) + 1; curr += strnlen ((char *) string, end - string);
printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
lineno, string); lineno, (int) (curr - string), string);
if (curr < end)
curr++;
break; break;
case DW_MACINFO_undef: case DW_MACINFO_undef:
READ_ULEB (lineno, curr, end); READ_ULEB (lineno, curr, end);
string = curr; string = curr;
curr += strnlen ((char *) string, end - string) + 1; curr += strnlen ((char *) string, end - string);
printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
lineno, string); lineno, (int) (curr - string), string);
if (curr < end)
curr++;
break; break;
case DW_MACINFO_vendor_ext: case DW_MACINFO_vendor_ext:
@ -5799,9 +5803,11 @@ display_debug_macinfo (struct dwarf_section *section,
READ_ULEB (constant, curr, end); READ_ULEB (constant, curr, end);
string = curr; string = curr;
curr += strnlen ((char *) string, end - string) + 1; curr += strnlen ((char *) string, end - string);
printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
constant, string); constant, (int) (curr - string), string);
if (curr < end)
curr++;
} }
break; break;
} }