From: "Andrew Burgess" <aburgess@broadcom.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: [PATCH] undefined printf format crashes gdb
Date: Tue, 13 Aug 2013 12:57:00 -0000 [thread overview]
Message-ID: <520A2D08.4080600@broadcom.com> (raw)
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
next reply other threads:[~2013-08-13 12:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-13 12:57 Andrew Burgess [this message]
2013-08-13 14:28 ` Pedro Alves
2013-08-13 16:08 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=520A2D08.4080600@broadcom.com \
--to=aburgess@broadcom.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox