Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2005:
[Freeciv-Dev] (PR#11748) Assert failure in mystrlcpy
Home

[Freeciv-Dev] (PR#11748) Assert failure in mystrlcpy

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11748) Assert failure in mystrlcpy
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Sat, 1 Jan 2005 08:36:19 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11748 >

> [vasc - Fri Dec 31 22:37:17 2004]:
> 
> This caused a crash in pubserver using S2_0:
> http://pubserver.freeciv.org/games/360712
> 
> To reproduce simply start a civserver and type:
> /'observe'
> 
> I think the bug is in utility/shared.c: get_tokens. Somehow, it is
> passing mystrlcpy 0 on the third argument. Then bang.

Here is a fix, including some minor cleanups. The confusing way
we parse commands probably should be reimplemented, but this stops
the crashes. To commit ASAP.

Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.354.2.17
diff -u -r1.354.2.17 stdinhand.c
--- server/stdinhand.c  24 Dec 2004 04:01:31 -0000      1.354.2.17
+++ server/stdinhand.c  1 Jan 2005 16:33:42 -0000
@@ -3261,10 +3261,8 @@
 
   /* Is it a comment or a blank line? */
   /* line is comment if the first non-whitespace character is '#': */
-  for (cptr_s = str; *cptr_s != '\0' && my_isspace(*cptr_s); cptr_s++) {
-    /* nothing */
-  }
-  if(*cptr_s == 0 || *cptr_s == '#') {
+  cptr_s = skip_leading_spaces(str);
+  if (*cptr_s == '\0' || *cptr_s == '#') {
     return FALSE;
   }
 
@@ -3345,9 +3343,7 @@
     return FALSE;
   }
 
-  for (; *cptr_s != '\0' && my_isspace(*cptr_s); cptr_s++) {
-    /* nothing */
-  }
+  cptr_s = skip_leading_spaces(cptr_s);
   sz_strlcpy(arg, cptr_s);
 
   cut_comment(arg);
Index: utility/shared.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/shared.c,v
retrieving revision 1.118.2.2
diff -u -r1.118.2.2 shared.c
--- utility/shared.c    13 Nov 2004 09:27:23 -0000      1.118.2.2
+++ utility/shared.c    1 Jan 2005 16:33:43 -0000
@@ -257,11 +257,13 @@
     }
 
     /* strip start/end quotes if they exist */
-    if ((str[0] == '"' && str[len - 1] == '"')
-       || (str[0] == '\'' && str[len - 1] == '\'')) {
-      len -= 2;
-      padlength = 1;           /* to set the string past the end quote */
-      str++;
+    if (len >= 2) {
+      if ((str[0] == '"' && str[len - 1] == '"')
+         || (str[0] == '\'' && str[len - 1] == '\'')) {
+       len -= 2;
+       padlength = 1;          /* to set the string past the end quote */
+       str++;
+      }
     }
   
     tokens[token] = fc_malloc(len + 1);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11748) Assert failure in mystrlcpy, Vasco Alexandre da Silva Costa <=