You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by jo...@apache.org on 2025/02/28 08:24:10 UTC

svn commit: r1924095 - in /httpd/httpd/trunk: changes-entries/pr69590.txt modules/lua/mod_lua.c

Author: jorton
Date: Fri Feb 28 08:24:10 2025
New Revision: 1924095

URL: http://svn.apache.org/viewvc?rev=1924095&view=rev
Log:
mod_lua: Fix memory handling in output filters.

* modules/lua/mod_lua.c (lua_output_filter_handle): Fix brigade
  iteration to use constant memory.

Submitted by: G.Grandes <guillermo.grandes gmail.com>
PR: 69590
Github: closes #517

Added:
    httpd/httpd/trunk/changes-entries/pr69590.txt
Modified:
    httpd/httpd/trunk/modules/lua/mod_lua.c

Added: httpd/httpd/trunk/changes-entries/pr69590.txt
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/changes-entries/pr69590.txt?rev=1924095&view=auto
==============================================================================
--- httpd/httpd/trunk/changes-entries/pr69590.txt (added)
+++ httpd/httpd/trunk/changes-entries/pr69590.txt Fri Feb 28 08:24:10 2025
@@ -0,0 +1,2 @@
+  *) mod_lua: Fix memory handling in LuaOutputFilter. PR 69590.
+     [Guillermo Grandes <guillermo.grandes gmail.com>]

Modified: httpd/httpd/trunk/modules/lua/mod_lua.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/mod_lua.c?rev=1924095&r1=1924094&r2=1924095&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/mod_lua.c (original)
+++ httpd/httpd/trunk/modules/lua/mod_lua.c Fri Feb 28 08:24:10 2025
@@ -472,14 +472,16 @@ static apr_status_t lua_output_filter_ha
     L = ctx->L;
     /* While the Lua function is still yielding, pass in buckets to the coroutine */
     if (!ctx->broken) {
-        for (pbktIn = APR_BRIGADE_FIRST(pbbIn);
-            pbktIn != APR_BRIGADE_SENTINEL(pbbIn);
-            pbktIn = APR_BUCKET_NEXT(pbktIn))
-            {
+        while (!APR_BRIGADE_EMPTY(pbbIn)) {
             const char *data;
             apr_size_t len;
             apr_bucket *pbktOut;
 
+            pbktIn = APR_BRIGADE_FIRST(pbbIn);
+            if (APR_BUCKET_IS_EOS(pbktIn)) {
+                break;
+            }
+
             /* read the bucket */
             apr_bucket_read(pbktIn,&data,&len,APR_BLOCK_READ);
 
@@ -513,10 +515,11 @@ static apr_status_t lua_output_filter_ha
                               lua_tostring(L, -1));
                 return HTTP_INTERNAL_SERVER_ERROR;
             }
+            apr_bucket_delete(pbktIn);
         }
         /* If we've safely reached the end, do a final call to Lua to allow for any 
         finishing moves by the script, such as appending a tail. */
-        if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pbbIn))) {
+        if (!APR_BRIGADE_EMPTY(pbbIn) && APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pbbIn))) {
             apr_bucket *pbktEOS;
             lua_pushnil(L);
             lua_setglobal(L, "bucket");