Skip to content

logmath_read ignores -mmap flag and crashes if mmio_file_read returns NULL #462

@dlyongemallo

Description

@dlyongemallo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions