Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] Re: (PR#13343) pubserver 2.0 crash in handle_nation_select
Home

[Freeciv-Dev] Re: (PR#13343) pubserver 2.0 crash in handle_nation_select

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13343) pubserver 2.0 crash in handle_nation_select_req
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 27 Jun 2005 10:42:23 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch fixes the crash by checking for the NULL case.  It also fixes
a related (non-fatal) problem with city names.  The underlying bug in
the player is not fixed.  The patch is for S2_0 but should be committed
to both branches.

-jason

Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.276.2.11
diff -u -r1.276.2.11 citytools.c
--- server/citytools.c  1 Apr 2005 00:42:29 -0000       1.276.2.11
+++ server/citytools.c  27 Jun 2005 17:41:45 -0000
@@ -256,7 +256,7 @@
 bool is_allowed_city_name(struct player *pplayer, const char *city_name,
                          char *error_buf, size_t bufsz)
 {
-  struct connection *pconn;
+  struct connection *pconn = find_conn_by_user(pplayer->username);
 
   /* Mode 1: A city name has to be unique for each player. */
   if (game.allowed_city_names == 1 &&
@@ -316,8 +316,7 @@
    * original nation are exhausted and the backup nations have non-ascii
    * names in them. */
   if (!is_ascii_name(city_name)
-      && (pconn = find_conn_by_user(pplayer->username))
-      && pconn->access_level != ALLOW_HACK) {
+      && (!pconn || pconn->access_level != ALLOW_HACK)) {
     if (error_buf) {
       my_snprintf(error_buf, bufsz,
                  _("%s is not a valid name. Only ASCII or "
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.201.2.10
diff -u -r1.201.2.10 srv_main.c
--- server/srv_main.c   16 Jan 2005 02:36:35 -0000      1.201.2.10
+++ server/srv_main.c   27 Jun 2005 17:41:46 -0000
@@ -1054,6 +1054,8 @@
                                   const char *name,
                                   char *error_buf, size_t bufsz)
 {
+  struct connection *pconn = find_conn_by_user(pplayer->username);
+
   /* An empty name is surely not allowed. */
   if (strlen(name) == 0) {
     if (error_buf) {
@@ -1099,8 +1101,10 @@
   /* To prevent abuse, only players with HACK access (usually local
    * connections) can use non-ascii names.  Otherwise players could use
    * confusing garbage names in multi-player games. */
+    /* FIXME: is there a better way to determine if a *player* has hack
+     * access? */
   if (!is_ascii_name(name)
-      && find_conn_by_user(pplayer->username)->access_level != ALLOW_HACK) {
+      && (!pconn || pconn->access_level != ALLOW_HACK)) {
     if (error_buf) {
       my_snprintf(error_buf, bufsz, _("Please choose a name containing "
                                      "only ASCII characters."));

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