Fix crash after recursive aliasing
authorH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 8 May 2015 10:56:17 +0000 (12:56 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 8 May 2015 10:56:17 +0000 (12:56 +0200)
The ICS translatese some commands (like 'storedmoves') to others
(like 'smoves'), which are then also subject to aliasing. Defining the
reverse substitution as alias then leads to infinite recursion.
The recursion is now limited to 10 levels, and makes the command fail
otherwise.

lasker-2.2.3/src/utils.c

index 9b3ee5c..cee39f4 100644 (file)
@@ -87,16 +87,21 @@ int mail_string_to_user(int p, char *subj, char *str)
 /* Process a command for a user */
 int pcommand(int p, char *comstr,...)
 {
+       static int recurse = 0;
        struct player *pp = &player_globals.parray[p];
        char *tmp;
        int retval;
        int current_socket = pp->socket;
        va_list ap;
        
+       if(recurse > 10) return COM_BADPARAMETERS; /* [HGM] guard against infinite recursion through bad aliasing */
+
        va_start(ap, comstr);
        vasprintf(&tmp, comstr, ap);
        va_end(ap);
+       recurse++;
        retval = process_input(current_socket, tmp);
+       recurse--;
        free(tmp);
        if (retval == COM_LOGOUT) {
                process_disconnection(current_socket);