From c03df92247333e5bf65bc663fab80fe7a87c0370 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sat, 15 May 2021 15:01:51 +0930 Subject: [PATCH] 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. --- binutils/ChangeLog | 5 +++++ binutils/dwarf.c | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 5fd8bc1fa15..b4f1af1957b 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,8 @@ +2021-05-15 Alan Modra + + * 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 * dwarf.c (display_debug_pubnames_worker): Delete initial_length_size. diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 878f4f766db..d184e5289ed 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -5780,17 +5780,21 @@ display_debug_macinfo (struct dwarf_section *section, case DW_MACINFO_define: READ_ULEB (lineno, curr, end); string = curr; - curr += strnlen ((char *) string, end - string) + 1; - printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), - lineno, string); + curr += strnlen ((char *) string, end - string); + printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"), + lineno, (int) (curr - string), string); + if (curr < end) + curr++; break; case DW_MACINFO_undef: READ_ULEB (lineno, curr, end); string = curr; - curr += strnlen ((char *) string, end - string) + 1; - printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), - lineno, string); + curr += strnlen ((char *) string, end - string); + printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"), + lineno, (int) (curr - string), string); + if (curr < end) + curr++; break; case DW_MACINFO_vendor_ext: @@ -5799,9 +5803,11 @@ display_debug_macinfo (struct dwarf_section *section, READ_ULEB (constant, curr, end); string = curr; - curr += strnlen ((char *) string, end - string) + 1; - printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), - constant, string); + curr += strnlen ((char *) string, end - string); + printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"), + constant, (int) (curr - string), string); + if (curr < end) + curr++; } break; } -- 2.30.2