aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2021-05-15 15:01:51 +0930
committerAlan Modra <amodra@gmail.com>2021-05-15 15:05:29 +0930
commitc03df92247333e5bf65bc663fab80fe7a87c0370 (patch)
treedf0e2e34a73dc8820d8ba44e51420846e8a5225f
parent35b2c89ec8bbcbf6894cb6ae408d97cbe06bbeb4 (diff)
downloadgdb-c03df92247333e5bf65bc663fab80fe7a87c0370.zip
gdb-c03df92247333e5bf65bc663fab80fe7a87c0370.tar.gz
gdb-c03df92247333e5bf65bc663fab80fe7a87c0370.tar.bz2
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.
-rw-r--r--binutils/ChangeLog5
-rw-r--r--binutils/dwarf.c24
2 files changed, 20 insertions, 9 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 5fd8bc1..b4f1af1 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,5 +1,10 @@
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>
+
* dwarf.c (display_debug_pubnames_worker): Delete initial_length_size.
Simplify length check. Constrain reads to length given by header.
diff --git a/binutils/dwarf.c b/binutils/dwarf.c
index 878f4f7..d184e52 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;
}