Skip to content

[2.4.x] Merge changes to mod_lua: LuaHook sections under 5.5, LuaHook + package path - #1041

Merged
covener merged 1 commit into
apache:2.4.xfrom
covener:2.4.x-mod_lua
Nov 16, 2026
Merged

covener merged 1 commit into
apache:2.4.xfrom
covener:2.4.x-mod_lua

Conversation

@covener

@covener covener commented Nov 15, 2026

Copy link
Copy Markdown
Member

Merge c774272 from trunk:

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

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 #1022 so the two merge cleanly in either
order.

Co-authored-by: Claude Fable 5.1 noreply@anthropic.com

The pick conflicted only on the include block at the top of modules/lua/mod_lua.c, where 2.4.x has an extra Windows getpid include; the code hunks are identical to trunk. The test/modules/lua suite does not exist on 2.4.x yet, so the pick adds the four files from this commit unchanged.

🤖 Generated with Claude Code

mod_lua: fix LuaScope server with inline blocks and .htaccess paths (apache#1030)

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>
(cherry picked from commit c774272)
@covener covener changed the title [2.4.x] Merge changes to mod_lua [2.4.x] Merge changes to mod_lua: LuaHook sections under 5.5, LuaHook + package path Nov 16, 2026

@arturobernalg arturobernalg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1

@covener
covener merged commit f1ac44b into apache:2.4.x Nov 16, 2026
36 checks passed
@covener
covener deleted the 2.4.x-mod_lua branch November 16, 2026 18:26
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.

2 participants