Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] undefined printf format crashes gdb
@ 2013-08-13 12:57 Andrew Burgess
  2013-08-13 14:28 ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2013-08-13 12:57 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] undefined printf format crashes gdb
  2013-08-13 12:57 [PATCH] undefined printf format crashes gdb Andrew Burgess
@ 2013-08-13 14:28 ` Pedro Alves
  2013-08-13 16:08   ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Alves @ 2013-08-13 14:28 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

On 08/13/2013 01:56 PM, Andrew Burgess wrote:
> 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?

OK.

Thanks,
-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] undefined printf format crashes gdb
  2013-08-13 14:28 ` Pedro Alves
@ 2013-08-13 16:08   ` Andrew Burgess
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2013-08-13 16:08 UTC (permalink / raw)
  To: gdb-patches

On 13/08/2013 3:28 PM, Pedro Alves wrote:
> On 08/13/2013 01:56 PM, Andrew Burgess wrote:
>> 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?
> 
> OK.
> 

Committed.

Thanks,
Andrew



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-13 16:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-13 12:57 [PATCH] undefined printf format crashes gdb Andrew Burgess
2013-08-13 14:28 ` Pedro Alves
2013-08-13 16:08   ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox