Fix player_login() not to print null pointer
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 16 Jan 2010 15:29:41 +0000 (16:29 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 19 Jan 2010 07:40:42 +0000 (08:40 +0100)
When the input line contains only whitespace, player->argp[0] is null
after parse().  This condition was not checked, comtch() returned
M_IGNORE, and code handling that printed the null pointer.  Some
systems (GNU, Windows) deal gracefully with printing null strings,
others crash.  Trivial to trigger remotely.

Before the fix, the value of parse() was assigned, but never used, and
that was spotted by the Clang Static Analyzer.

src/lib/player/login.c

index 428f77d1efa1306c4e1d701363ddac2ea2f09e47..7f66a23a0883e5d8d15caf420be4d954c7edc9dd 100644 (file)
@@ -98,6 +98,10 @@ player_login(void *ud)
            continue;
        }
        ac = parse(buf, space, player->argp, NULL, NULL, NULL);
+       if (ac <= 0) {
+           pr_id(player, C_BADCMD, "Can't parse command\n");
+           continue;
+       }
        cmd = comtch(player->argp[0], login_coms, 0);
        if (cmd < 0) {
            pr_id(player, C_BADCMD, "Command %s not found\n", player->argp[0]);