]> git.pond.sub.org Git - empserver/commitdiff
Fix validation of threshold's threshold argument
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 20 Jul 2008 02:35:23 +0000 (22:35 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 25 Jul 2008 12:16:29 +0000 (08:16 -0400)
There were two checks meant to enforce positive numbers, both dating
back to the earliest known versions of the code, and both wrong.

The first one applied only to thresholds given with the command, not
ones prompted for, and it incorrectly rejected numbers starting with +
or prefixed by whitespace.  Remove it.

The second one failed to reject negative numbers when prefixed by
whitespace.  Fix.

Fortunately, the update doesn't conjure up stuff to satisfy negative
thresholds.

src/lib/commands/thre.c

index 64c27a61bc37c1b2f0e8c1cecba465886e75fd3f..b888aeecf8e1abe2476ad5de08400e304eb2f7b3 100644 (file)
@@ -58,12 +58,7 @@ thre(void)
     if (!snxtsct(&nstr, player->argp[2]))
        return RET_SYN;
     type = ip->i_uid;
-    if (player->argp[3] && *player->argp[3] &&
-       (*player->argp[3] < '0' || *player->argp[3] > '9')) {
-       pr("Threshold must be a number\n");
-       return RET_SYN;
-    }
-    while (!player->aborted && nxtsct(&nstr, &sect)) {
+    while (nxtsct(&nstr, &sect)) {
        if (!player->owner)
            continue;
        val = sect.sct_dist[type];
@@ -76,12 +71,14 @@ thre(void)
                    xyas(nstr.x, nstr.y, player->cnum),
                    dchr[sect.sct_type].d_name);
        if ((p = getstarg(player->argp[3], prompt, buf)) == 0)
-           return RET_FAIL;
+           return RET_SYN;
+       if (!*p)
+           continue;
        if (!check_sect_ok(&sect))
            return RET_FAIL;
-       if (*p == '\0' || *p == '-')
-           continue;
        thresh = atoi(p);
+       if (thresh < 0)
+           return RET_SYN;
        if (thresh > ITEM_MAX)
            thresh = ITEM_MAX;
        if ((val > 0) && (val == thresh)) {