From: H.G. Muller Date: Wed, 3 Feb 2010 12:42:09 +0000 (+0100) Subject: Fix of ancient WinBoard bug: check value of int options X-Git-Tag: v4.4.3.20100220~21 X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=098f667a67c83a5c0b8b8d46f4fe0c8d7f9149da;p=xboard.git Fix of ancient WinBoard bug: check value of int options Only strings of digits are accepted now. --- diff --git a/winboard/winboard.c b/winboard/winboard.c index 1e65185..a7705c4 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -1462,6 +1462,15 @@ ExitArgError(char *msg, char *badArg) exit(2); } +int +ValidateInt(char *s) +{ + char *p = s; + if(*p == '-' || *p == '+') p++; + while(*p) if(!isdigit(*p++)) ExitArgError("Bad integer value", s); + return atoi(s); +} + /* Command line font name parser. NULL name means do nothing. Syntax like "Courier New:10.0 bi" or "Arial:10" or "Arial:10b" For backward compatibility, syntax without the colon is also @@ -1773,19 +1782,19 @@ ParseArgs(GetFunc get, void *cl) switch (ad->argType) { case ArgInt: - *(int *) ad->argLoc = atoi(argValue); + *(int *) ad->argLoc = ValidateInt(argValue); break; case ArgX: - *(int *) ad->argLoc = atoi(argValue) + boardX; // [HGM] placement: translate stored relative to absolute + *(int *) ad->argLoc = ValidateInt(argValue) + boardX; // [HGM] placement: translate stored relative to absolute break; case ArgY: - *(int *) ad->argLoc = atoi(argValue) + boardY; // (this is really kludgey, it should be done where used...) + *(int *) ad->argLoc = ValidateInt(argValue) + boardY; // (this is really kludgey, it should be done where used...) break; case ArgZ: - *(int *) ad->argLoc = atoi(argValue); + *(int *) ad->argLoc = ValidateInt(argValue); EnsureOnScreen(&boardX, &boardY, minX, minY); break;