[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 >
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 -r1.334 stdinhand.c
223a224
> static bool valid_endyear(int value, const char **reject_message);
889c890
< N_("Year the game ends"), "", NULL,
---
> N_("Year the game ends"), "", valid_endyear,
3565c3566
< int val, cmd;
---
> int val, cmd, i;
3622c3623,3635
< } 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) {
3647c3660,3672
< } 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) {
5110a5136,5149
> 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;
> }
>
> /**************************************************************************
- [Freeciv-Dev] (PR#7414) Patch to fix endyear bug and tighten validation,
Ciaran Mac Lochlainn <=
|
|