diff options
| author | Markus Uhlin <markus@nifty-networks.net> | 2026-03-23 19:50:44 +0100 |
|---|---|---|
| committer | Markus Uhlin <markus@nifty-networks.net> | 2026-03-23 19:50:44 +0100 |
| commit | a1d1c7809dcc36971812add8966a01fd28b4db75 (patch) | |
| tree | c35a68bca507a030e05398bf2bd78a6d24cab4f3 /FICS/formula.c | |
| parent | 06a696970bd181c799fa547b94df4c8090c1665b (diff) | |
ExplainFormula: check for snprintf() truncation
Diffstat (limited to 'FICS/formula.c')
| -rw-r--r-- | FICS/formula.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/FICS/formula.c b/FICS/formula.c index a7ee006..226fcfa 100644 --- a/FICS/formula.c +++ b/FICS/formula.c @@ -604,11 +604,20 @@ ExplainFormula(game *g, textlist **clauses) which = ChooseClauses(challenged, challenged->formula); for (i = 0; i < MAX_FORMULA; i++) { + int ret; + if ((which & (1 << i)) == 0) continue; dummy_index = 0; CheckFormula(g, i, &dummy_index, OPTYPE_NONE, &value, 1); - snprintf(txt, sizeof txt, "%d", value); + + ret = snprintf(txt, sizeof txt, "%d", value); + + if (is_too_long(ret, sizeof txt)) { + warnx("%s: snprintf() truncated", __func__); + continue; + } + SaveTextListEntry(Cur, txt, i); Cur = &(*Cur)->next; } |
