From fa9551a286073acff5b0178380868e3ed7a1b6f5 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 31 Dec 2023 22:46:49 +0100 Subject: Check the return of fgets() and trim the newline using strcspn() --- FICS/playerdb.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'FICS/playerdb.c') diff --git a/FICS/playerdb.c b/FICS/playerdb.c index 065d1d2..01edb3c 100644 --- a/FICS/playerdb.c +++ b/FICS/playerdb.c @@ -431,9 +431,13 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) pp->l_stats.sterr = (ls / 10.0); pp->bug_stats.sterr = (bugs / 10.0); - fgets(tmp2, sizeof tmp2, fp); - tmp2[strlen(tmp2) - 1] = '\0'; - pp->prompt = xstrdup(tmp2); + if (fgets(tmp2, sizeof tmp2, fp) == NULL) { + fprintf(stderr, "Player %s is corrupt\n", parray[p].name); + return; + } else { + tmp2[strcspn(tmp2, "\n")] = '\0'; + pp->prompt = xstrdup(tmp2); + } if (fscanf(fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", -- cgit v1.2.3