Author: sveinung
Date: Wed Jul 23 16:25:38 2014
New Revision: 25699

URL: http://svn.gna.org/viewcvs/freeciv?rev=25699&view=rev
Log:
Check that ruleset supplied specialist names won't break savegames

Savegames stores the number of each kind of specialists a city has using the
specialist rule name in the entry name. A specialist rule name must therefore be
a valid entry name in a section file.

See patch #4972

Modified:
    trunk/server/rssanity.c
    trunk/utility/registry_ini.c
    trunk/utility/registry_ini.h

Modified: trunk/server/rssanity.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/rssanity.c?rev=25699&r1=25698&r2=25699&view=diff
==============================================================================
--- trunk/server/rssanity.c     (original)
+++ trunk/server/rssanity.c     Wed Jul 23 16:25:38 2014
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -569,6 +569,14 @@
                     "Specialists have conflicting or invalid requirements!");
       ok = FALSE;
     }
+
+    /* Specialist rulenames are used as an entry name in savegames. */
+    if (!is_secfile_entry_name_valid(specialist_rule_name(psp))) {
+      ruleset_error(LOG_ERROR,
+                    "Specialist rule name \"%s\" unusable in savegames!",
+                    specialist_rule_name(psp));
+      ok = FALSE;
+    }
   } specialist_type_iterate_end;
 
   /* Extras */

Modified: trunk/utility/registry_ini.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/registry_ini.c?rev=25699&r1=25698&r2=25699&view=diff
==============================================================================
--- trunk/utility/registry_ini.c        (original)
+++ trunk/utility/registry_ini.c        Wed Jul 23 16:25:38 2014
@@ -226,7 +226,7 @@
 /**************************************************************************
   Ensure name is correct to use it as section or entry name.
 **************************************************************************/
-static bool check_name(const char *name)
+bool is_secfile_entry_name_valid(const char *name)
 {
   static const char *const allowed = "_.,-[]";
 
@@ -2623,7 +2623,7 @@
     return NULL;
   }
 
-  if (!check_name(name)) {
+  if (!is_secfile_entry_name_valid(name)) {
     SECFILE_LOG(secfile, NULL, "\"%s\" is not a valid section name.",
                 name);
     return NULL;
@@ -2714,7 +2714,7 @@
     return FALSE;
   }
 
-  if (!check_name(name)) {
+  if (!is_secfile_entry_name_valid(name)) {
     SECFILE_LOG(secfile, psection,
                 "\"%s\" is not a valid section name for section \"%s\".",
                 name, psection->name);
@@ -2856,7 +2856,7 @@
     return NULL;
   }
 
-  if (!check_name(name)) {
+  if (!is_secfile_entry_name_valid(name)) {
     SECFILE_LOG(secfile, psection, "\"%s\" is not a valid entry name.",
                 name);
     return NULL;
@@ -3033,7 +3033,7 @@
     return FALSE;
   }
 
-  if (!check_name(name)) {
+  if (!is_secfile_entry_name_valid(name)) {
     SECFILE_LOG(secfile, psection,
                 "\"%s\" is not a valid entry name for entry \"%s\".",
                 name, pentry->name);

Modified: trunk/utility/registry_ini.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/utility/registry_ini.h?rev=25699&r1=25698&r2=25699&view=diff
==============================================================================
--- trunk/utility/registry_ini.h        (original)
+++ trunk/utility/registry_ini.h        Wed Jul 23 16:25:38 2014
@@ -595,6 +595,9 @@
 bool entry_str_escaped(const struct entry *pentry);
 bool entry_str_set_escaped(struct entry *pentry, bool escaped);
 
+/* Validation functions */
+bool is_secfile_entry_name_valid(const char *name);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to