Check cfg_meta's result before reading a row's default in default_number and gfx_cfg_window_size.

cfg.c default_number, which cfg_int and cfg_double use for a set value that does not parse, read cfg_meta(name)->def
without a check, so a key without a row whose value was set and unparsable crashed there (the verifier's probe: a
segmentation fault inside default_number). gfx_present.c gfx_cfg_window_size did the same for WINDOW_SIZE. Neither
is reachable today: every unguarded value read has a row (tests/cfg_rows_check.py holds it so), the three guarded
ones use cfg_bool, and WINDOW_SIZE has a row.

default_number gives 0 for a key without a row; gfx_cfg_window_size falls back to 1920x1080 when the row or its
default is missing. Taking the device profile's default there (1280x800 on a Steam Deck) would change what players
get and is left for approval.

Reproduced before the change with the new case in tests/cfg_parse_check.py (cfg_int and cfg_double of an unset row's
key set to "abc" crashed the program); with the change both give 0 and the check passes, as do the cfg rows checks
and the compile checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-13 17:40:00 -05:00
parent 5b9ed9ed12
commit 153295b64c
4 changed files with 18 additions and 5 deletions

View File

@@ -985,9 +985,11 @@ static const char *cfg_memo_get(const char *name, int kind) {
const char *cfg_get(const char *name) { return cfg_memo_get(name, 0); }
const char *cfg_value(const char *name) { return cfg_memo_get(name, 1); }
// The row's default as a number, for a set value that does not parse.
// The row's default as a number, for a set value that does not parse; 0 for a key without a row, whose set value
// cfg_value hands out without one (tests/cfg_rows_check.py keeps such reads guarded).
static double default_number(const char *name) {
return strtod(cfg_meta(name)->def, NULL);
const CfgMeta *m = cfg_meta(name);
return m ? strtod(m->def, NULL) : 0;
}
double cfg_double(const char *name) {

View File

@@ -179,8 +179,10 @@ int gfx_cfg_fullscreen(void) { return cfg_bool("NX2NAVI_FULLSCREEN"); }
void gfx_cfg_window_size(int *w, int *h) {
int x = 0, y = 0;
if (sscanf(cfg_value("NX2NAVI_WINDOW_SIZE"), "%dx%d", &x, &y) != 2 || x < 640 || y < 360 || x > 7680 || y > 4320)
sscanf(cfg_meta("WINDOW_SIZE")->def, "%dx%d", &x, &y); // unparsable or out of range: the default
if (sscanf(cfg_value("NX2NAVI_WINDOW_SIZE"), "%dx%d", &x, &y) != 2 || x < 640 || y < 360 || x > 7680 || y > 4320) {
const CfgMeta *m = cfg_meta("WINDOW_SIZE"); // unparsable or out of range: the default
if (!m || sscanf(m->def, "%dx%d", &x, &y) != 2) x = 1920, y = 1080;
}
*w = x;
*h = y;
}