Skip to content

[2.4.x] Merge changes to mod_lua - #1108

Open
notroj wants to merge 20 commits into
apache:2.4.xfrom
notroj:2.4.x-mod_lua
Open

notroj wants to merge 20 commits into
apache:2.4.xfrom
notroj:2.4.x-mod_lua

Conversation

@notroj

@notroj notroj commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Merge 2dc8153, 03d702b, b0b9228, 052b6d4, 45e5b0a, 357f42a, 5ef7405, dcea9a2, 3d83642, e70e4c7, fa875d0, 08c876d, 0a23d2a, d68dbd4, 7d75a3e, 1cda948, 01f1a64, 1a7fafc, 5343bb3, 20627d3 from trunk:

  • test/modules/lua: New test suite.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

mod_lua: Cap memory use of r:wsread():

  • modules/lua/lua_request.c (lua_temp_ctx_t, lua_temp_ctx,
    lua_temp_pool, req_call): New.
    (req_dispatch): Push request methods as a req_call closure.
    (lua_websocket_read): Allocate from the temporary pool, and the mask
    on the stack.

  • changes-entries/lua-wsread-memory.txt: Add.

Fixes: 731d18d (SVN r1522030)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.c (lua_websocket_readbytes): Loop until
    the requested length has been read.

  • changes-entries/lua-fixes.txt: Add.

Fixes: 11a3fcb (SVN r1901502)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.c (lua_websocket_read): Return empty data
    frames; answer a ping with its payload; skip a pong; stop at a close
    frame, an unmasked frame or an oversized control frame; check the
    64-bit length before narrowing it.

  • changes-entries/lua-fixes.txt: Update.

Fixes: 731d18d (SVN r1522030)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.c (lua_ap_regex): Pass the full size of
    the matches array to ap_regexec().

  • changes-entries/lua-fixes.txt: Update.

Fixes: 49fcd96 (SVN r1433967)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

mod_lua: Cap memory use of r:regex():

  • modules/lua/lua_request.c (lua_ap_regex): Free the compiled
    pattern, push captures without copying them into r->pool, and use
    a stack buffer for error messages.

  • changes-entries/lua-wsread-memory.txt: Update.

Fixes: 3b6cdb0 (SVN r1420377)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.c (lua_ap_set_document_root,
    lua_ap_set_context_info): Copy the strings into r->pool.

  • changes-entries/lua-fixes.txt: Update.

Fixes: 3b6cdb0 (SVN r1420377)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

mod_lua: Cap memory use of string methods such as r:escape():

  • modules/lua/lua_request.c (req_construct_url, req_escape_html,
    lua_apr_b64encode, lua_apr_b64decode, lua_ap_unescape,
    lua_ap_escape, lua_apr_htpassword, lua_ap_expr,
    lua_ap_runtime_dir_relative, lua_ap_getdir, lua_ap_os_escape_path,
    lua_ap_escape_logitem, lua_ivm_get, lua_ivm_set): Allocate from the
    temporary pool.

  • changes-entries/lua-wsread-memory.txt: Update.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

mod_lua: Cap memory use of r:md5(), r:sha1() and other methods:

  • modules/lua/lua_request.c (lua_apr_md5): Hash with apr_md5_update()
    into a stack buffer.
    (lua_apr_sha1, lua_ap_scoreboard_worker): Use stack buffers.
    (read_cfg_tree): Drop the request_rec argument; build the directive
    string with lua_pushfstring().
    (lua_ap_get_config, lua_ap_get_active_config): Adjust.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

mod_lua: Cap memory use of request table and option fields:

  • modules/lua/lua_request.c (req_table): New function.
    (req_headers_in, req_headers_out, req_err_headers_out,
    req_subprocess_env, req_notes): Use it.
    (req_flags_string): New function.
    (lua_ap_options, lua_ap_allowoverrides): Rebuild the string only
    when the flags change.

  • test/modules/lua/test_003_request.py (test_lua_003_04_fields): New
    test.

  • test/modules/lua/htdocs/test1/lua/fields.lua: New file.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • test/modules/lua/test_001_websocket.py (test_lua_001_07_wspeek_empty,
    test_lua_001_08_wspeek_read): New tests.

  • test/modules/lua/htdocs/test1/lua/wsread.lua (handle): Answer "peek"
    and "peekread".

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.c (lua_websocket_peek): Use a speculative
    read, return false for an empty brigade, and allocate from the
    temporary pool.

  • changes-entries/lua-fixes.txt: Update.

Fixes: c92f2cf (SVN r1570208)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

mod_lua: Cap memory use of r:sendfile():

  • modules/lua/lua_request.c (lua_ap_sendfile): Allocate the file and
    brigade from the temporary pool in place of ap_send_fd(); fail if
    apr_stat() fails.

  • test/modules/lua/test_003_request.py (test_lua_003_05_sendfile):
    New test.

  • test/modules/lua/htdocs/test1/lua/sendfile.lua,
    test/modules/lua/htdocs/test1/lua/file.txt: New files.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • test/modules/lua/test_004_body.py: New test suite.

  • test/modules/lua/test_003_request.py (test_lua_003_06_limit_req_body,
    test_lua_003_07_mpm_query_unknown,
    test_lua_003_08_scoreboard_worker_range): New tests.

  • test/modules/lua/htdocs/test1/lua/body.lua,
    test/modules/lua/htdocs/test1/lua/info.lua: New files.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

mod_lua: Cap memory use of r:requestbody():

  • modules/lua/lua_request.c (lua_read_body): Collect the body as it
    arrives rather than allocating the Content-Length up front; refuse
    a length which does not fit in an apr_size_t; return only OK, DONE
    or an HTTP status.
    (lua_write_body): Take the filename and open the file, truncating
    it, after checking the length against a new maxsize argument; drop
    the apr_size_t cast; fail on a short read; return only OK, DONE or
    an HTTP status; set *size to the bytes written.
    (lua_ap_requestbody): Return nil and a message for a body over the
    limit when storing it to a file too.
    (req_parsebody): Terminate the buffer at the flattened length.

  • changes-entries/lua-wsread-memory.txt,
    changes-entries/lua-fixes.txt: Update.

Fixes: 1a50285 (SVN r1420286)
Fixes: 49fcd96 (SVN r1433967)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.c (lua_ap_scoreboard_worker): Return nothing
    for indexes outside the scoreboard.
    (lua_ap_mpm_query): Return nothing if the query fails.

Fixes: b2605d2 (SVN r1610491)
Fixes: 49fcd96 (SVN r1433967)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.h (APL_REQ_FUNTYPE_INT64): New field type.

  • modules/lua/lua_request.c (req_dispatch): Handle it.
    (lua_ap_started, lua_ap_limit_req_body): Return apr_int64_t, and
    register as APL_REQ_FUNTYPE_INT64.

  • test/modules/lua/test_003_request.py (test_lua_003_09_started): New
    test.

Fixes: 2e9e74f (SVN r1370158)

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.c (MODLUA_MAX_BASE64): New macro.
    (lua_apr_b64encode, lua_apr_b64decode): Refuse a string longer than
    MODLUA_MAX_BASE64.
    (lua_apr_sha1): Pass the string to apr_sha1_update() in pieces which
    fit its length argument.

  • test/modules/lua/test_003_request.py (test_lua_003_10_digests,
    test_lua_003_11_base64_max): New tests.

  • test/modules/lua/htdocs/test1/lua/info.lua: Add md5, sha1 and
    base64_max.

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com

  • modules/lua/lua_request.c (lua_websocket_greet): Close the
    connection after the request once upgraded.

Co-Authored-By: Claude Fable 5.2 noreply@anthropic.com

  • modules/lua/lua_request.c (lua_ap_sendfile): Send nothing for an
    empty file.

Co-Authored-By: Claude Fable 5.2 noreply@anthropic.com

🤖 Generated with Claude Code

notroj and others added 20 commits November 27, 2026 15:29
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2dc8153)
* modules/lua/lua_request.c (lua_temp_ctx_t, lua_temp_ctx,
  lua_temp_pool, req_call): New.
  (req_dispatch): Push request methods as a req_call closure.
  (lua_websocket_read): Allocate from the temporary pool, and the mask
  on the stack.

* changes-entries/lua-wsread-memory.txt: Add.

Fixes: 731d18d (SVN r1522030)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 03d702b)
  the requested length has been read.

* changes-entries/lua-fixes.txt: Add.

Fixes: 11a3fcb (SVN r1901502)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit b0b9228)
  frames; answer a ping with its payload; skip a pong; stop at a close
  frame, an unmasked frame or an oversized control frame; check the
  64-bit length before narrowing it.

* changes-entries/lua-fixes.txt: Update.

Fixes: 731d18d (SVN r1522030)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 052b6d4)
  the matches array to ap_regexec().

* changes-entries/lua-fixes.txt: Update.

Fixes: 49fcd96 (SVN r1433967)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 45e5b0a)
* modules/lua/lua_request.c (lua_ap_regex): Free the compiled
  pattern, push captures without copying them into r->pool, and use
  a stack buffer for error messages.

* changes-entries/lua-wsread-memory.txt: Update.

Fixes: 3b6cdb0 (SVN r1420377)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 357f42a)
  lua_ap_set_context_info): Copy the strings into r->pool.

* changes-entries/lua-fixes.txt: Update.

Fixes: 3b6cdb0 (SVN r1420377)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 5ef7405)
* modules/lua/lua_request.c (req_construct_url, req_escape_html,
  lua_apr_b64encode, lua_apr_b64decode, lua_ap_unescape,
  lua_ap_escape, lua_apr_htpassword, lua_ap_expr,
  lua_ap_runtime_dir_relative, lua_ap_getdir, lua_ap_os_escape_path,
  lua_ap_escape_logitem, lua_ivm_get, lua_ivm_set): Allocate from the
  temporary pool.

* changes-entries/lua-wsread-memory.txt: Update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit dcea9a2)
* modules/lua/lua_request.c (lua_apr_md5): Hash with apr_md5_update()
  into a stack buffer.
  (lua_apr_sha1, lua_ap_scoreboard_worker): Use stack buffers.
  (read_cfg_tree): Drop the request_rec argument; build the directive
  string with lua_pushfstring().
  (lua_ap_get_config, lua_ap_get_active_config): Adjust.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 3d83642)
* modules/lua/lua_request.c (req_table): New function.
  (req_headers_in, req_headers_out, req_err_headers_out,
  req_subprocess_env, req_notes): Use it.
  (req_flags_string): New function.
  (lua_ap_options, lua_ap_allowoverrides): Rebuild the string only
  when the flags change.

* test/modules/lua/test_003_request.py (test_lua_003_04_fields): New
  test.

* test/modules/lua/htdocs/test1/lua/fields.lua: New file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit e70e4c7)
  test_lua_001_08_wspeek_read): New tests.

* test/modules/lua/htdocs/test1/lua/wsread.lua (handle): Answer "peek"
  and "peekread".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit fa875d0)
  read, return false for an empty brigade, and allocate from the
  temporary pool.

* changes-entries/lua-fixes.txt: Update.

Fixes: c92f2cf (SVN r1570208)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 08c876d)
* modules/lua/lua_request.c (lua_ap_sendfile): Allocate the file and
  brigade from the temporary pool in place of ap_send_fd(); fail if
  apr_stat() fails.

* test/modules/lua/test_003_request.py (test_lua_003_05_sendfile):
  New test.

* test/modules/lua/htdocs/test1/lua/sendfile.lua,
  test/modules/lua/htdocs/test1/lua/file.txt: New files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 0a23d2a)
* test/modules/lua/test_003_request.py (test_lua_003_06_limit_req_body,
  test_lua_003_07_mpm_query_unknown,
  test_lua_003_08_scoreboard_worker_range): New tests.

* test/modules/lua/htdocs/test1/lua/body.lua,
  test/modules/lua/htdocs/test1/lua/info.lua: New files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit d68dbd4)
* modules/lua/lua_request.c (lua_read_body): Collect the body as it
  arrives rather than allocating the Content-Length up front; refuse
  a length which does not fit in an apr_size_t; return only OK, DONE
  or an HTTP status.
  (lua_write_body): Take the filename and open the file, truncating
  it, after checking the length against a new maxsize argument; drop
  the apr_size_t cast; fail on a short read; return only OK, DONE or
  an HTTP status; set *size to the bytes written.
  (lua_ap_requestbody): Return nil and a message for a body over the
  limit when storing it to a file too.
  (req_parsebody): Terminate the buffer at the flattened length.

* changes-entries/lua-wsread-memory.txt,
  changes-entries/lua-fixes.txt: Update.

Fixes: 1a50285 (SVN r1420286)
Fixes: 49fcd96 (SVN r1433967)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 7d75a3e)
  for indexes outside the scoreboard.
  (lua_ap_mpm_query): Return nothing if the query fails.

Fixes: b2605d2 (SVN r1610491)
Fixes: 49fcd96 (SVN r1433967)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 1cda948)
* modules/lua/lua_request.c (req_dispatch): Handle it.
  (lua_ap_started, lua_ap_limit_req_body): Return apr_int64_t, and
  register as APL_REQ_FUNTYPE_INT64.

* test/modules/lua/test_003_request.py (test_lua_003_09_started): New
  test.

Fixes: 2e9e74f (SVN r1370158)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 01f1a64)
  (lua_apr_b64encode, lua_apr_b64decode): Refuse a string longer than
  MODLUA_MAX_BASE64.
  (lua_apr_sha1): Pass the string to apr_sha1_update() in pieces which
  fit its length argument.

* test/modules/lua/test_003_request.py (test_lua_003_10_digests,
  test_lua_003_11_base64_max): New tests.

* test/modules/lua/htdocs/test1/lua/info.lua: Add md5, sha1 and
  base64_max.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

(cherry picked from commit 1a7fafc)
  connection after the request once upgraded.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
(cherry picked from commit 5343bb3)
  empty file.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
(cherry picked from commit 20627d3)
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