Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH] PR gdb/11092: Fix index overflow
Date: Mon, 17 May 2010 16:10:00 -0000	[thread overview]
Message-ID: <m3eiha7bsa.fsf@hase.home> (raw)

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."


             reply	other threads:[~2010-05-17 16:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-17 16:10 Andreas Schwab [this message]
2010-05-17 16:50 ` Tom Tromey

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=m3eiha7bsa.fsf@hase.home \
    --to=schwab@redhat.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