Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2005:
[Freeciv-Dev] (PR#14032) civserver crash on /debug
Home

[Freeciv-Dev] (PR#14032) civserver crash on /debug

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#14032) civserver crash on /debug
From: "Mateusz Stefek" <mstefek@xxxxxxxxx>
Date: Tue, 20 Sep 2005 05:38:18 -0700
Reply-to: bugs@xxxxxxxxxxx

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

> [per - Mon Sep 19 11:01:12 2005]:
> 
> Weird one.
> 
>   - Per

Debug without arguments may crash the server.
The patch is self-explanatory - I'm applying it immediatelly.
--
mateusz
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.354.2.41
diff -u -r1.354.2.41 stdinhand.c
--- server/stdinhand.c  20 Sep 2005 10:35:04 -0000      1.354.2.41
+++ server/stdinhand.c  20 Sep 2005 12:36:09 -0000
@@ -2250,12 +2250,14 @@
     return TRUE; /* whatever! */
   }
 
-  if (str != NULL || strlen(str) > 0) {
+  if (str != NULL && strlen(str) > 0) {
     sz_strlcpy(buf, str);
     ntokens = get_tokens(buf, arg, 3, TOKEN_DELIMITERS);
+  } else {
+    ntokens = 0;
   }
 
-  if (strcmp(arg[0], "player") == 0) {
+  if (ntokens > 0 && strcmp(arg[0], "player") == 0) {
     struct player *pplayer;
     enum m_pre_result match_result;
 
@@ -2277,7 +2279,7 @@
       cmd_reply(CMD_DEBUG, caller, C_OK, _("%s debugged"), pplayer->name);
       /* TODO: print some info about the player here */
     }
-  } else if (strcmp(arg[0], "city") == 0) {
+  } else if (ntokens > 0 && strcmp(arg[0], "city") == 0) {
     int x, y;
     struct tile *ptile;
     struct city *pcity;
@@ -2308,7 +2310,7 @@
       CITY_LOG(LOG_NORMAL, pcity, "debugged");
       pcity->ai.next_recalc = 0; /* force recalc of city next turn */
     }
-  } else if (strcmp(arg[0], "units") == 0) {
+  } else if (ntokens > 0 && strcmp(arg[0], "units") == 0) {
     int x, y;
     struct tile *ptile;
 
@@ -2335,7 +2337,7 @@
                  unit_owner(punit)->name, unit_name(punit->type));
       }
     } unit_list_iterate_end;
-  } else if (strcmp(arg[0], "unit") == 0) {
+  } else if (ntokens > 0 && strcmp(arg[0], "unit") == 0) {
     int id;
     struct unit *punit;
 

[Prev in Thread] Current Thread [Next in Thread]