diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-12-02 14:27:52 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-12-02 14:27:52 +0100 |
commit | 56bf28d72a3cda58fbce373a975dc6668e187f86 (patch) | |
tree | 65b855e38d12ec84da2c76eea7c0b6d6013e932c /FICS | |
parent | b321f7532c2f3a1a00b4dfa121b950aff4f44f7d (diff) |
ReadV1PlayerFmt: handle fgets() nullret
Diffstat (limited to 'FICS')
-rw-r--r-- | FICS/playerdb.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/FICS/playerdb.c b/FICS/playerdb.c index 93c81e8..e1da179 100644 --- a/FICS/playerdb.c +++ b/FICS/playerdb.c @@ -539,7 +539,10 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) if (pp->num_plan > 0) { for (i = 0; i < pp->num_plan; i++) { - fgets(tmp2, sizeof tmp2, fp); + if (fgets(tmp2, sizeof tmp2, fp) == NULL) { + warnx("%s: bad plan: feof %s", __func__, file); + return; + } if (!(len = strlen(tmp2))) { fprintf(stderr, "FICS: Error bad plan in " @@ -557,7 +560,11 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) if (pp->num_formula > 0) { for (i = 0; i < pp->num_formula; i++) { - fgets(tmp2, sizeof tmp2, fp); + if (fgets(tmp2, sizeof tmp2, fp) == NULL) { + warnx("%s: bad formula: feof %s", __func__, + file); + return; + } if (!(len = strlen(tmp2))) { fprintf(stderr, "FICS: Error bad formula in " @@ -573,8 +580,12 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) } } - fgets(tmp2, sizeof tmp2, fp); - tmp2[strlen(tmp2) - 1] = '\0'; + if (fgets(tmp2, sizeof tmp2, fp) == NULL) { + warnx("%s: fgets() error", __func__); + return; + } + + tmp2[strcspn(tmp2, "\n")] = '\0'; if (!strcmp(tmp2, "NONE")) pp->formula = NULL; @@ -583,7 +594,10 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) if (pp->numAlias > 0) { for (i = 0; i < pp->numAlias; i++) { - fgets(tmp2, sizeof tmp2, fp); + if (fgets(tmp2, sizeof tmp2, fp) == NULL) { + warnx("%s: bad alias: feof %s", __func__, file); + return; + } if (!(len = strlen(tmp2))) { fprintf(stderr, "FICS: Error bad alias in " |