-
Notifications
You must be signed in to change notification settings - Fork 730
Description
logmath_read() in src/util/logmath.c unconditionally attempts to memory-map model files, ignoring the -mmap configuration flag. All other callers of mmio_file_read (bin_mdef.c, s2_semi_mgau.c, ptm_mgau.c) check ps_config_bool(config, "mmap") before calling mmio_file_read, but logmath_read does not: it always sets do_mmap = 1 (line 231) and only disables it for alignment or endianness reasons.
Additionally, when mmio_file_read returns NULL (e.g., because mmap(MAP_SHARED) failed), the code on line 246 unconditionally dereferences the result, which crashes on any platform where mmap fails at runtime, regardless of whether -mmap no was set in the config. (In particular, this happens in Emscripten/WASM.)
Suggested fix: Check for NULL return from mmio_file_read (on line 245) and fall back to the fread path (lines 248-258), similar to bin_mdef.c:410-412. Additionally, logmath_read should check the -mmap config flag.