Skip to content

mod_lua: fix LuaScope server with inline blocks and .htaccess paths - #1030

Open
covener wants to merge 1 commit into
apache:trunkfrom
covener:lua-copy-vm-spec
Open

covener wants to merge 1 commit into
apache:trunkfrom
covener:lua-copy-vm-spec

Conversation

@covener

@covener covener commented Nov 14, 2026

Copy link
Copy Markdown
Member

With LuaScope server, copy_vm_spec() copies the VM spec into the process pool for the shared VM reslist. It used apr_pstrdup() on the compiled bytecode of a <LuaHook...> block, which stops at the first NUL byte of the Lua header while the stored length is kept, so the hook function never got defined and every request failed with AH01478. The package path arrays were also only shallow-copied, leaving dangling strings when LuaPackagePath or LuaPackageCPath comes from .htaccess.

Writing the test also turned up a config-time crash with Lua 5.5: lua_dump() now pushes a table onto the stack while dumping, and the luaL_Buffer used by the writer assumes its own box is at the stack top. The bytecode is now collected in an ap_varbuf off the Lua stack.

Adds a test/modules/lua pytest suite; the new test fails on the bytecode copy before this change. The suite's conftest.py and env.py are identical to those in #1022 so the two merge cleanly in either order.

🤖 Generated with Claude Code

copy_vm_spec() copies the VM spec into the process pool for the
server-scoped VM reslist, but copied the compiled bytecode of a
<LuaHook...> block with apr_pstrdup(), truncating it at the first NUL
byte of the Lua header while keeping the full length. The hook
function was never defined and every request failed with
"Unable to find entry function". Use apr_pmemdup() with the length.

The package path arrays were copied with apr_array_copy(), which only
copies the pointers, so with LuaPackagePath or LuaPackageCPath set in
.htaccess the strings lived in a request pool and were dangling when
the reslist constructed a further VM later. Deep-copy the strings.

While adding a test for this, the <LuaHook...> block reader crashed
at config time when built against Lua 5.5: lua_dump() now pushes a
table on the stack while dumping, and the luaL_Buffer used by the
writer assumes its own box is at the stack top. Accumulate the
bytecode in an ap_varbuf instead, off the Lua stack.

Add a test/modules/lua pytest suite with a test that fails on the
bytecode copy before this change. Its conftest.py and env.py match
the suite proposed in PR apache#1022 so the two merge cleanly in either
order.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant