This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [commit] objc-lang.c, classes_info, avoid string overrun


Yao Qi wrote:
On 03/01/2011 09:46 AM, Michael Snyder wrote:
-	  if (sizeof (myregexp) < strlen (regexp) + 1)
+	  if (sizeof (myregexp) < strlen (regexp) + 4)
 	    error (_("Regexp is too long: %s"), regexp);
 	  strcpy(myregexp, regexp);

It is a little bit confusing when people read this code. We may need a short comment here.


Okey dokey, see attached.




2011-03-01  Michael Snyder  <msnyder@vmware.com>

	* objc-lang.c (selectors_info): Add explanitory comment.
	(classes_info): Ditto.

Index: objc-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/objc-lang.c,v
retrieving revision 1.94
diff -u -p -u -p -r1.94 objc-lang.c
--- objc-lang.c	1 Mar 2011 01:44:24 -0000	1.94
+++ objc-lang.c	1 Mar 2011 18:49:41 -0000
@@ -720,6 +720,7 @@ selectors_info (char *regexp, int from_t
 	strcpy(myregexp, ".*]");
       else
 	{
+	  /* Allow a few extra bytes because of the strcat below.  */
 	  if (sizeof (myregexp) < strlen (regexp) + 4)
 	    error (_("Regexp is too long: %s"), regexp);
 	  strcpy(myregexp, regexp);
@@ -863,6 +864,7 @@ classes_info (char *regexp, int from_tty
     strcpy(myregexp, ".* ");	/* Null input: match all objc classes.  */
   else
     {
+      /* Allow a few extra bytes because of the strcat below.  */
       if (sizeof (myregexp) < strlen (regexp) + 4)
 	error (_("Regexp is too long: %s"), regexp);
       strcpy(myregexp, regexp);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]