This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] undefined printf format crashes gdb
- From: "Andrew Burgess" <aburgess at broadcom dot com>
- To: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Tue, 13 Aug 2013 13:56:40 +0100
- Subject: [PATCH] undefined printf format crashes gdb
Current gdb HEAD:
(gdb) printf "%#p", 0
./printcmd.c:2655: internal-error: ui_printf: Assertion `*p == 'p' && *(p + 1) == '\0'' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y
With my patch:
(gdb) printf "%#p", 0
Inappropriate modifiers to format specifier 'p' in printf
The man page for printf (on my machine) says # on pointers is undefined,
but my undefined seems better than the current undefined :)
OK to apply?
Thanks,
Andrew
gdb/ChangeLog
2013-08-13 Andrew Burgess <aburgess@broadcom.com>
* common/format.c (parse_format_string): Don't allow '#' flag for
pointer arguments in format string.
testsuite/ChangeLog
2013-08-13 Andrew Burgess <aburgess@broadcom.com
* gdb.base/printcmds.exp (test_printf): Add test for printf of
pointer with various flags.
diff --git a/gdb/common/format.c b/gdb/common/format.c
index 1bdd253..985e0e4 100644
--- a/gdb/common/format.c
+++ b/gdb/common/format.c
@@ -263,7 +263,9 @@ parse_format_string (const char **arg)
this_argclass = ptr_arg;
if (lcount || seen_h || seen_big_l)
bad = 1;
- if (seen_prec || seen_zero || seen_space || seen_plus)
+ if (seen_prec)
+ bad = 1;
+ if (seen_hash || seen_zero || seen_space || seen_plus)
bad = 1;
break;
diff --git a/gdb/testsuite/gdb.base/printcmds.exp b/gdb/testsuite/gdb.base/printcmds.exp
index 4f88382..60e4a7f 100644
--- a/gdb/testsuite/gdb.base/printcmds.exp
+++ b/gdb/testsuite/gdb.base/printcmds.exp
@@ -734,6 +734,12 @@ proc test_printf {} {
gdb_test "printf \"%.234\", 0" "Incomplete format specifier at end of format string"
gdb_test "printf \"%-\", 0" "Incomplete format specifier at end of format string"
gdb_test "printf \"%-23\", 0" "Incomplete format specifier at end of format string"
+
+ # Test for invalid printf flags on pointer types.
+ gdb_test "printf \"%#p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
+ gdb_test "printf \"% p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
+ gdb_test "printf \"%0p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
+ gdb_test "printf \"%+p\", 0" "Inappropriate modifiers to format specifier 'p' in printf"
}
#Test printing DFP values with printf