aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-11-28 21:46:45 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2024-11-28 21:46:45 +0100
commitbf0daae7f32422349d3365a428cf16cb700fdaef (patch)
tree7da696d3d259b730fecd8829af278ae70ca2124f
parenta1db6a85e6c68a3cb8e49dd311634534db245249 (diff)
Added width spec and fixed ignored retvals
-rw-r--r--FICS/makerank.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/FICS/makerank.c b/FICS/makerank.c
index 8815a3c..daece45 100644
--- a/FICS/makerank.c
+++ b/FICS/makerank.c
@@ -46,6 +46,8 @@ GetPlayerInfo(char *fileName, ENTRY *e)
}
if (!strcmp(line, "v 1\n")) {
+ _Static_assert(ARRAY_SIZE(e->name) > 19, "Array too little");
+
if (fgets(line, sizeof line, fp) == NULL ||
sscanf(line, "%19s", e->name) != 1) {
warnx("%s: fgets() or sscanf() error", __func__);
@@ -79,10 +81,24 @@ GetPlayerInfo(char *fileName, ENTRY *e)
done = 1;
} else {
do {
- sscanf(line, "%s", field);
+ _Static_assert(ARRAY_SIZE(field) > 19,
+ "Unexpected array length");
+ _Static_assert(ARRAY_SIZE(NameWithCase) > 29,
+ "Unexpected array length");
+
+ if (sscanf(line, "%19s", field) != 1) {
+ warnx("%s: sscanf() error", __func__);
+ fclose(fp);
+ return 0;
+ }
if (!strcmp(field, "Name:")) {
- sscanf(line, "%*s %s", NameWithCase);
+ if (sscanf(line, "%*s %29s", NameWithCase) != 1) {
+ warnx("%s: expected name with case",
+ __func__);
+ fclose(fp);
+ return 0;
+ }
if (strcasecmp(e->name, NameWithCase)) {
printf("TROUBLE: %s's handle is "