From 679bf294d1a0924d7783ab6748f1ff327200373b Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 20 May 2024 00:26:01 +0200 Subject: Size-bounded string copying --- FICS/gamedb.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/FICS/gamedb.c b/FICS/gamedb.c index f8da9fd..7b1d44e 100644 --- a/FICS/gamedb.c +++ b/FICS/gamedb.c @@ -44,6 +44,10 @@ #include "rmalloc.h" #include "utils.h" +#if __linux__ +#include +#endif + /* * This should be enough to hold any game up to at least 250 moves. If * we overwrite this, the server will crash. @@ -206,7 +210,7 @@ game_time_str(int wt, int winc, int bt, int binc) static char tstr[50] = { '\0' }; if ((!wt) && (!winc)) { // Untimed - strcpy(tstr, ""); + (void) strlcpy(tstr, "", sizeof tstr); return tstr; } @@ -1142,13 +1146,13 @@ ReadOneV1Move(FILE *fp, move_t *m) PieceChar = PieceToChar(piecetype(piece) | WHITE); if (PieceChar == 'K' && m->fromFile == 4 && m->toFile == 6) { - strcpy(m->algString, "O-O"); - strcpy(m->moveString, "o-o"); + mstrlcpy(m->algString, "O-O", sizeof(m->algString)); + mstrlcpy(m->moveString, "o-o", sizeof(m->moveString)); } else if (PieceChar == 'K' && m->fromFile == 4 && m->toFile == 2) { - strcpy(m->algString, "O-O-O"); - strcpy(m->moveString, "o-o-o"); + mstrlcpy(m->algString, "O-O-O", sizeof(m->algString)); + mstrlcpy(m->moveString, "o-o-o", sizeof(m->moveString)); } else { i = 0; m->algString[i++] = PieceChar; -- cgit v1.2.3