From: H.G. Muller Date: Wed, 29 Jun 2011 11:53:00 +0000 (+0200) Subject: Fix crash on making too-long FEN X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=55517059338842241bcc8d82b1dec21e92b138da;p=xboard.git Fix crash on making too-long FEN The buffer for in PositionToFEN was only 128 bytes, which was not enough for large boards such as 19x19 Go. It is enlarged to MSG_SIZ(512) now. There also is some approximate overflow checking added (but it is not fool proof in case there are holdings...) --- diff --git a/backend.c b/backend.c index cc5fb3a..a1c3c86 100644 --- a/backend.c +++ b/backend.c @@ -15821,7 +15821,7 @@ PositionToFEN(move, overrideCastling) { int i, j, fromX, fromY, toX, toY; int whiteToPlay; - char buf[128]; + char buf[MSG_SIZ]; char *p, *q; int emptycount; ChessSquare piece; @@ -15832,6 +15832,7 @@ PositionToFEN(move, overrideCastling) /* Piece placement data */ for (i = BOARD_HEIGHT - 1; i >= 0; i--) { + if(MSG_SIZ - (p - buf) < BOARD_RGHT - BOARD_LEFT + 20) { *p = 0; return StrSave(buf); } emptycount = 0; for (j = BOARD_LEFT; j < BOARD_RGHT; j++) { if (boards[move][i][j] == EmptySquare) {