Description: Do not abort the IGS session on an unparsable server line When a line from the IGS server did not match cgoban's hard-coded sscanf format, the client popped up a "Cgoban Error" dialog referring to an old Linux ELF sscanf bug and stopped interpreting that class of message. On a present-day server this misfires on otherwise harmless lines and makes the connection look broken. . Replace the five misleading pop-ups (game list, kibitz, result, say-detect and the player "connected" notice) with a single diagnostic line on stderr that prints the exact offending text, then skip just that line and carry on. Author: Martin A. Godisch --- --- a/src/client/game.c +++ b/src/client/game.c @@ -315,6 +315,23 @@ } +/* + * Render an untrusted server line for a diagnostic message: printable + * ASCII only and truncated, so hostile control/escape bytes can never + * reach the user's terminal. + */ +static const char *cliSafeLine(const char *s) { + static char out[81]; + int i; + + for (i = 0; (i < (int)sizeof(out) - 1) && s[i]; ++i) + out[i] = (((unsigned char)s[i] >= 0x20) && ((unsigned char)s[i] < 0x7f)) ? + s[i] : '.'; + out[i] = '\0'; + return(out); +} + + void cliGameList_gotGameInfo(CliGameList *gl, const char *buf) { int gameNum, move, size, handicap, byTime, observers; float komi; @@ -332,8 +349,7 @@ if (matches != 12) { if (!gl->elfBugReported) { gl->elfBugReported = TRUE; - cgoban_createMsgWindow(gl->data->cg, "Cgoban Error", - msg_gameBadElf); + fprintf(stderr, "cgoban: ignoring unparsable IGS line: %s\n", cliSafeLine(buf)); } return; } @@ -458,8 +474,7 @@ if (args != 2) { if (!gl->elfBugReported) { gl->elfBugReported = TRUE; - cgoban_createMsgWindow(gl->data->cg, "Cgoban Error", - msg_gameBadElf); + fprintf(stderr, "cgoban: ignoring unparsable IGS line: %s\n", cliSafeLine(buf)); } return; } @@ -711,8 +726,7 @@ if(args != 2) { if (!gl->elfBugReported) { gl->elfBugReported = TRUE; - cgoban_createMsgWindow(gl->data->cg, "Cgoban Error", - msg_gameBadElf); + fprintf(stderr, "cgoban: ignoring unparsable IGS line: %s\n", cliSafeLine(buf)); } return; } @@ -998,8 +1012,7 @@ if (matches != 1) { if (!list->elfBugReported) { list->elfBugReported = TRUE; - cgoban_createMsgWindow(list->data->cg, "Cgoban Error", - msg_gameBadElf); + fprintf(stderr, "cgoban: ignoring unparsable IGS line: %s\n", cliSafeLine(str_chars(tell))); } return(FALSE); } --- a/src/client/player.c +++ b/src/client/player.c @@ -403,6 +403,23 @@ } +/* + * Render an untrusted server line for a diagnostic message: printable + * ASCII only and truncated, so hostile control/escape bytes can never + * reach the user's terminal. + */ +static const char *cliSafeLine(const char *s) { + static char out[81]; + int i; + + for (i = 0; (i < (int)sizeof(out) - 1) && s[i]; ++i) + out[i] = (((unsigned char)s[i] >= 0x20) && ((unsigned char)s[i] < 0x7f)) ? + s[i] : '.'; + out[i] = '\0'; + return(out); +} + + void cliPlayerList_connected(CliPlayerList *pl, const char *buf) { char name[50], rank[50]; int args, i, playerNum; @@ -412,8 +429,7 @@ if (args != 2) { if (!pl->elfBugReported) { pl->elfBugReported = TRUE; - cgoban_createMsgWindow(pl->data->cg, "Cgoban Error", - msg_gameBadElf); + fprintf(stderr, "cgoban: ignoring unparsable IGS line: %s\n", cliSafeLine(buf)); } return; }