Skip to content

test/modules/lua: Don't require /proc in body.lua - #1112

Merged
covener merged 1 commit into
apache:trunkfrom
covener:lua-test-no-proc
Nov 28, 2026
Merged

covener merged 1 commit into
apache:trunkfrom
covener:lua-test-no-proc

Conversation

@covener

@covener covener commented Nov 28, 2026

Copy link
Copy Markdown
Member

body.lua read /proc/self/status unconditionally to report the child's RSS, so test_lua_004_01_read returned a 500 and failed on platforms without /proc, such as macOS. Return 0 there instead; the tests which compare RSS already skip without /proc.

test/ is kept in sync with 2.4.x, so this also needs to go into the 2.4.x merge PR for the mod_lua changes (#1108).

  is no /proc/self/status, rather than failing the request, so that
  test_lua_004_01_read passes on macOS.
@covener
covener merged commit da67ab4 into apache:trunk Nov 28, 2026
46 checks passed
covener added a commit to notroj/httpd that referenced this pull request Nov 28, 2026
* test/modules/lua/htdocs/test1/lua/body.lua (rss): Return 0 where there

  is no /proc/self/status, rather than failing the request, so that
  test_lua_004_01_read passes on macOS.

(cherry picked from commit da67ab4)
notroj added a commit that referenced this pull request Nov 28, 2026
* test/modules/lua: New test suite.

(cherry picked from commit 2dc8153)

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)

(cherry picked from commit 03d702b)

* 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)

(cherry picked from commit b0b9228)

* 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)

(cherry picked from commit 052b6d4)

* 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)

(cherry picked from commit 45e5b0a)

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)

(cherry picked from commit 357f42a)

* 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)

(cherry picked from commit 5ef7405)

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.

(cherry picked from commit dcea9a2)

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.

(cherry picked from commit 3d83642)

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.

(cherry picked from commit e70e4c7)

* 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".

(cherry picked from commit fa875d0)

* 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)

(cherry picked from commit 08c876d)

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.

(cherry picked from commit 0a23d2a)

* 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.

(cherry picked from commit d68dbd4)

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)

(cherry picked from commit 7d75a3e)

* 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)

(cherry picked from commit 1cda948)

* 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)

(cherry picked from commit 01f1a64)

* 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.

(cherry picked from commit 1a7fafc)

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

(cherry picked from commit 5343bb3)

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

(cherry picked from commit 20627d3)

test/modules/lua: Don't require /proc in body.lua (#1112)

* test/modules/lua/htdocs/test1/lua/body.lua (rss): Return 0 where there

  is no /proc/self/status, rather than failing the request, so that
  test_lua_004_01_read passes on macOS.

(cherry picked from commit da67ab4)

Submitted by: jorton, covener
Reviewed by: covener

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Eric Covener <covener@apache.org>
GitHub: #1108
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