[Freeciv-Dev] (PR#7414) Patch to fix endyear bug and tighten validation
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7414 >
Trying again, with unified diff against current cvs:
This patch tightens up the validation of boolean and integer server
parameters. It also adds a validation function for the endyear
parameter, which will only allow values of endyear which are greater
than game.year.
With this patch, boolean server parameters must not contain any
characters other than 0 and 1. Integer server parameters can only
contain +- and 0-9.
Index: stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.334
diff -u -r1.334 stdinhand.c
--- stdinhand.c 31 Jul 2004 03:57:26 -0000 1.334
+++ stdinhand.c 2 Aug 2004 15:47:12 -0000
@@ -221,6 +221,7 @@
*/
static bool valid_notradesize(int value, const char **reject_message);
static bool valid_fulltradesize(int value, const char **reject_message);
+static bool valid_endyear(int value, const char **reject_message);
static bool autotoggle(bool value, const char **reject_message);
static bool is_valid_allowtake(const char *allow_take,
const char **error_string);
@@ -886,7 +887,7 @@
GEN_INT("endyear", game.end_year,
SSET_META, SSET_SOCIOLOGY, SSET_TO_CLIENT, SSET_VITAL,
- N_("Year the game ends"), "", NULL,
+ N_("Year the game ends"), "", valid_endyear,
GAME_MIN_END_YEAR, GAME_MAX_END_YEAR, GAME_DEFAULT_END_YEAR)
GEN_INT( "timeout", game.timeout,
@@ -3562,7 +3563,7 @@
static bool set_command(struct connection *caller, char *str, bool check)
{
char command[MAX_LEN_CONSOLE_LINE], arg[MAX_LEN_CONSOLE_LINE], *cptr_s,
*cptr_d;
- int val, cmd;
+ int val, cmd, i;
struct settings_s *op;
bool do_update;
char buffer[500];
@@ -3619,7 +3620,19 @@
if (sscanf(arg, "%d", &val) != 1) {
cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value must be an integer."));
return FALSE;
- } else if (val != 0 && val != 1) {
+ }
+ /* make sure the input string only contains digits */
+ for (i=0;; i++) {
+ if (arg[i] == '\0' ) {
+ break;
+ }
+ if (arg[i] < '0' || arg[i] > '1') {
+ cmd_reply(CMD_SET, caller, C_SYNTAX,
+ _("The parameter %s should only contain digits 0-1."),
op->name);
+ return FALSE;
+ }
+ }
+ if (val != 0 && val != 1) {
cmd_reply(CMD_SET, caller, C_SYNTAX,
_("Value out of range (minimum: 0, maximum: 1)."));
return FALSE;
@@ -3644,7 +3657,19 @@
if (sscanf(arg, "%d", &val) != 1) {
cmd_reply(CMD_SET, caller, C_SYNTAX, _("Value must be an integer."));
return FALSE;
- } else if (val < op->int_min_value || val > op->int_max_value) {
+ }
+ /* make sure the input string only contains digits */
+ for (i=0;; i++) {
+ if (arg[i] == '\0' ) {
+ break;
+ }
+ if ((arg[i] < '0' || arg[i] > '9') && arg[i] != '-' && arg[i] != '+') {
+ cmd_reply(CMD_SET, caller, C_SYNTAX,
+ _("The parameter %s should only contain +- and 0-9."),
op->name);
+ return FALSE;
+ }
+ }
+ if (val < op->int_min_value || val > op->int_max_value) {
cmd_reply(CMD_SET, caller, C_SYNTAX,
_("Value out of range (minimum: %d, maximum: %d)."),
op->int_min_value, op->int_max_value);
@@ -5108,6 +5133,20 @@
}
/**************************************************************************
+ Verify that endyear is not before the current year
+**************************************************************************/
+static bool valid_endyear(int value, const char **reject_message)
+{
+ if (value > GAME_START_YEAR && value >= game.year) {
+ return TRUE;
+ }
+
+ *reject_message = _("endyear must not be before the current game year, "
+ "keeping old value.");
+ return FALSE;
+}
+
+/**************************************************************************
A callback invoked when autotoggle is set.
**************************************************************************/
static bool autotoggle(bool value, const char **reject_message)
|
|