From abc30cfcd930bb822e5e4b46fe5b54203a0e1025 Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Sun, 14 Apr 2013 02:53:36 +0000 Subject: [PATCH] Return early with an error instead of returning an incomplete match table. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1467721 13f79535-47bb-0310-9956-ffa450edef68 --- modules/lua/lua_request.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 75ba18a4e4..b153cbd466 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -921,6 +921,16 @@ static int lua_ap_regex(lua_State *L) return 2; } + if (regex.re_nsub > MODLUA_MAX_REG_MATCH) { + lua_pushboolean(L, 0); + err = apr_palloc(r->pool, 64); + apr_snprintf(err, 64, + "regcomp found %d matches; only %d allowed.", + regex.re_nsub, MODLUA_MAX_REG_MATCH); + lua_pushstring(L, err); + return 2; + } + rv = ap_regexec(®ex, source, MODLUA_MAX_REG_MATCH, matches, 0); if (rv == AP_REG_NOMATCH) { lua_pushboolean(L, 0); @@ -928,7 +938,7 @@ static int lua_ap_regex(lua_State *L) } lua_newtable(L); - for (i = 0; i <= regex.re_nsub && i <= MODLUA_MAX_REG_MATCH; i++) { + for (i = 0; i <= regex.re_nsub; i++) { lua_pushinteger(L, i); if (matches[i].rm_so >= 0 && matches[i].rm_eo >= 0) lua_pushstring(L, -- 2.40.0