* [PATCH] PR gdb/11092: Fix index overflow
@ 2010-05-17 16:10 Andreas Schwab
2010-05-17 16:50 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Schwab @ 2010-05-17 16:10 UTC (permalink / raw)
To: gdb-patches
The length parameter of c_printstr can be -1 meaning NUL terminated.
Compute real length before its first use as an index.
Andreas.
2010-05-17 Andreas Schwab <schwab@redhat.com>
PR gdb/11092
* c-lang.c (c_printstr): Compute real length of NUL terminated
string at first.
Index: c-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/c-lang.c,v
retrieving revision 1.85
diff -a -u -p -a -u -p -r1.85 c-lang.c
--- c-lang.c 13 May 2010 23:53:32 -0000 1.85
+++ c-lang.c 17 May 2010 15:58:18 -0000
@@ -390,6 +390,19 @@ c_printstr (struct ui_file *stream, stru
int finished = 0;
int need_escape = 0;
+ if (length == -1)
+ {
+ unsigned long current_char = 1;
+
+ for (i = 0; current_char; ++i)
+ {
+ QUIT;
+ current_char = extract_unsigned_integer (string + i * width,
+ width, byte_order);
+ }
+ length = i;
+ }
+
/* If the string was not truncated due to `set print elements', and
the last byte of it is a null, we don't print that, in traditional C
style. */
@@ -424,19 +437,6 @@ c_printstr (struct ui_file *stream, stru
return;
}
- if (length == -1)
- {
- unsigned long current_char = 1;
-
- for (i = 0; current_char; ++i)
- {
- QUIT;
- current_char = extract_unsigned_integer (string + i * width,
- width, byte_order);
- }
- length = i;
- }
-
/* Arrange to iterate over the characters, in wchar_t form. */
iter = make_wchar_iterator (string, length * width, encoding, width);
cleanup = make_cleanup_wchar_iterator (iter);
--
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E
"And now for something completely different."
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] PR gdb/11092: Fix index overflow
2010-05-17 16:10 [PATCH] PR gdb/11092: Fix index overflow Andreas Schwab
@ 2010-05-17 16:50 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2010-05-17 16:50 UTC (permalink / raw)
To: Andreas Schwab; +Cc: gdb-patches
>>>>> "Andreas" == Andreas Schwab <schwab@redhat.com> writes:
Andreas> The length parameter of c_printstr can be -1 meaning NUL terminated.
Andreas> Compute real length before its first use as an index.
Andreas> 2010-05-17 Andreas Schwab <schwab@redhat.com>
Andreas> PR gdb/11092
Andreas> * c-lang.c (c_printstr): Compute real length of NUL terminated
Andreas> string at first.
This is ok. Thanks for fixing this.
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-05-17 16:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-17 16:10 [PATCH] PR gdb/11092: Fix index overflow Andreas Schwab
2010-05-17 16:50 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox