aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/playerdb.c
diff options
context:
space:
mode:
Diffstat (limited to 'FICS/playerdb.c')
-rw-r--r--FICS/playerdb.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/FICS/playerdb.c b/FICS/playerdb.c
index 309a8fc..eedaf39 100644
--- a/FICS/playerdb.c
+++ b/FICS/playerdb.c
@@ -43,6 +43,8 @@
Markus Uhlin 25/03/29 player_remove_request:
fixed overflowed array index
read/write.
+ Markus Uhlin 25/04/02 add_to_list: added an upper
+ limit for the list size.
*/
#include "stdinclude.h"
@@ -409,10 +411,14 @@ add_to_list(FILE *fp, enum ListWhich lw, int *size, int p)
#define SCAN_STR "%1023s"
- if (*size <= 0)
+ if (*size <= 0 || *size > MAX_GLOBAL_LIST_SIZE) {
+// warnx("%s: illegal list size (%d)", __func__, *size);
return -2;
+ }
+
while ((*size)-- > 0 && fscanf(fp, SCAN_STR, buf) == 1)
list_add(p, lw, buf);
+
return (*size <= 0 ? 0 : -1);
}
@@ -578,6 +584,23 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version)
pp->timeOfReg = array[0];
pp->totalTime = array[1];
+ if (pp->num_plan > MAX_PLAN) {
+ warnx("Player %s is corrupt\nToo many plans (%d)",
+ parray[p].name,
+ pp->num_plan);
+ return;
+ } else if (pp->num_formula > MAX_FORMULA) {
+ warnx("Player %s is corrupt\nToo many formulas (%d)",
+ parray[p].name,
+ pp->num_formula);
+ return;
+ } else if (pp->numAlias > MAX_ALIASES) {
+ warnx("Player %s is corrupt\nToo many aliases (%d)",
+ parray[p].name,
+ pp->numAlias);
+ return;
+ }
+
if (pp->num_plan > 0) {
for (i = 0; i < pp->num_plan; i++) {
if (fgets(tmp2, sizeof tmp2, fp) == NULL) {
@@ -834,9 +857,11 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file)
* num_plan
*/
- parray[p].num_plan = atoi(value);
-
- if (parray[p].num_plan > 0) {
+ if ((parray[p].num_plan = atoi(value)) > MAX_PLAN) {
+ warnx("%s: %s: too many plans (%d)", __func__, file,
+ parray[p].num_plan);
+ return -1;
+ } else if (parray[p].num_plan > 0) {
for (i = 0; i < parray[p].num_plan; i++) {
if (fgets(tmp, sizeof tmp, fp) == NULL) {
@@ -858,15 +883,19 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file)
xstrdup(tmp) : NULL);
}
}
+ } else {
+ /* null */;
}
} else if (!strcmp(attr, "num_formula:")) {
/*
* num_formula
*/
- parray[p].num_formula = atoi(value);
-
- if (parray[p].num_formula > 0) {
+ if ((parray[p].num_formula = atoi(value)) > MAX_FORMULA) {
+ warnx("%s: %s: too many formulas (%d)", __func__, file,
+ parray[p].num_formula);
+ return -1;
+ } else if (parray[p].num_formula > 0) {
for (i = 0; i < parray[p].num_formula; i++) {
if (fgets(tmp, sizeof tmp, fp) == NULL) {
warnx("%s: bad formula: feof %s",
@@ -887,6 +916,8 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file)
xstrdup(tmp) : NULL);
}
}
+ } else {
+ /* null */;
}
} else if (!strcmp(attr, "formula:")) {
/*
@@ -899,9 +930,11 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file)
* num_alias
*/
- parray[p].numAlias = atoi(value);
-
- if (parray[p].numAlias > 0) {
+ if ((parray[p].numAlias = atoi(value)) > MAX_ALIASES) {
+ warnx("%s: %s: too many aliases (%d)", __func__, file,
+ parray[p].numAlias);
+ return -1;
+ } else if (parray[p].numAlias > 0) {
for (i = 0; i < parray[p].numAlias; i++) {
if (fgets(tmp, sizeof tmp, fp) == NULL) {
warnx("%s: bad alias: feof %s",
@@ -928,6 +961,8 @@ got_attr_value_player(int p, char *attr, char *value, FILE *fp, char *file)
xstrdup(tmp1);
}
}
+ } else {
+ /* null */;
}
} else if (!strcmp(attr, "num_censor:")) {
/*