Skip to content

os_bitand/os_bitor/os_bitxor/os_x2c allocate script-controlled sizes without checking: 10 unchecked mallocs in the MVS glue #13

Description

@mgrossmann

The vendored Lua 5.4 core is clean (allocator NULL handled everywhere via LUA_ERRMEM), but the hand-written MVS glue in src/loslib.c allocates buffers sized by the script's string lengths and dereferences them immediately:

  • src/loslib.c:580,581,582os_bitand buf1/buf2/resp, memcpy into them two lines later
  • src/loslib.c:623,624,625os_bitor, same shape
  • src/loslib.c:666,667,668os_bitxor, same shape
  • src/loslib.c:706os_x2c, writes resp[j++] at :719

Since libc370#81 (fixed by libc370#82, in the sysroot as of 2026-08-09) malloc() returns NULL on shortage, so each of these is an S0C4 — in the lua370 CLI, or inside httpd when the same code runs under httplua.

Fix: allocate through Lua's own luaM_/luaL_Buffer machinery (which raises LUA_ERRMEM properly) or check and luaL_error — the sizes are attacker/script-controlled, so the failure must land in the script's error handling, not in the host process.

Sweep context: mvslovers/libc370#81 (comment)

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