From 796a9c0565610447a890d1576880ae52b7e1680b Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Mon, 2 Dec 2024 15:18:53 +0100 Subject: got_attr_value_player: check the return of fgets() --- FICS/playerdb.c | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'FICS') diff --git a/FICS/playerdb.c b/FICS/playerdb.c index a82f3b9..2ac7389 100644 --- a/FICS/playerdb.c +++ b/FICS/playerdb.c @@ -795,7 +795,12 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file) if (parray[p].num_plan > 0) { for (i = 0; i < parray[p].num_plan; i++) { - fgets(tmp, sizeof tmp, fp); + + if (fgets(tmp, sizeof tmp, fp) == NULL) { + warnx("%s: bad plan: feof %s", + __func__, file); + return -1; + } if (!(len = strlen(tmp))) { fprintf(stderr, "FICS: Error bad plan " @@ -818,7 +823,11 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file) if (parray[p].num_formula > 0) { for (i = 0; i < parray[p].num_formula; i++) { - fgets(tmp, sizeof tmp, fp); + if (fgets(tmp, sizeof tmp, fp) == NULL) { + warnx("%s: bad formula: feof %s", + __func__, file); + return -1; + } if (!(len = strlen(tmp))) { fprintf(stderr, "FICS: Error bad " @@ -847,7 +856,11 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file) if (parray[p].numAlias > 0) { for (i = 0; i < parray[p].numAlias; i++) { - fgets(tmp, sizeof tmp, fp); + if (fgets(tmp, sizeof tmp, fp) == NULL) { + warnx("%s: bad alias: feof %s", + __func__, file); + return -1; + } if (!(len = strlen(tmp))) { fprintf(stderr, "FICS: Error bad alias " @@ -877,7 +890,11 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file) i = atoi(value); while (i--) { - fgets(tmp, sizeof tmp, fp); + if (fgets(tmp, sizeof tmp, fp) == NULL) { + warnx("%s: bad censor: feof %s", + __func__, file); + return -1; + } if (!(len = strlen(tmp)) || len == 1) { // blank lines // do occur! @@ -892,7 +909,11 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file) i = atoi(value); while (i--) { - fgets(tmp, sizeof tmp, fp); + if (fgets(tmp, sizeof tmp, fp) == NULL) { + warnx("%s: bad notify: feof %s", + __func__, file); + return -1; + } if (!(len = strlen(tmp)) || len == 1) { // blank lines // do occur! @@ -907,7 +928,11 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file) i = atoi(value); while (i--) { - fgets(tmp, sizeof tmp, fp); + if (fgets(tmp, sizeof tmp, fp) == NULL) { + warnx("%s: bad noplay: feof %s", + __func__, file); + return -1; + } if (!(len = strlen(tmp)) || len == 1) { // blank lines // do occur! @@ -922,7 +947,11 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file) i = atoi(value); while (i--) { - fgets(tmp, sizeof tmp, fp); + if (fgets(tmp, sizeof tmp, fp) == NULL) { + warnx("%s: bad gnotify: feof %s", + __func__, file); + return -1; + } if (!(len = strlen(tmp)) || len == 1) { // blank lines // do occur! -- cgit v1.2.3