From cced512116b33589f34bd1b3e7fedefa73472a98 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Fri, 23 Nov 2018 01:33:16 -0500 Subject: [PATCH] [mod_cml] parse query string without modifying it --- src/mod_cml_lua.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/mod_cml_lua.c b/src/mod_cml_lua.c index 7f6901e2..daf15917 100644 --- a/src/mod_cml_lua.c +++ b/src/mod_cml_lua.c @@ -64,7 +64,7 @@ static int c_to_lua_push(lua_State *L, int tbl, const char *key, size_t key_len, static int cache_export_get_params(lua_State *L, int tbl, buffer *qrystr) { size_t is_key = 1; - size_t i, len; + size_t i, len, klen = 0; char *key = NULL, *val = NULL; key = qrystr->ptr; @@ -76,9 +76,7 @@ static int cache_export_get_params(lua_State *L, int tbl, buffer *qrystr) { case '=': if (is_key) { val = qrystr->ptr + i + 1; - - qrystr->ptr[i] = '\0'; - + klen = (size_t)(val - key - 1); is_key = 0; } @@ -87,13 +85,9 @@ static int cache_export_get_params(lua_State *L, int tbl, buffer *qrystr) { case '\0': /* fin symbol */ if (!is_key) { /* we need at least a = since the last & */ - - /* terminate the value */ - qrystr->ptr[i] = '\0'; - c_to_lua_push(L, tbl, - key, strlen(key), - val, strlen(val)); + key, klen, + val, (size_t)(qrystr->ptr + i - val)); } key = qrystr->ptr + i + 1; @@ -157,13 +151,7 @@ int cache_parse_lua(server *srv, connection *con, plugin_data *p, buffer *fn) { /* register GET parameter */ lua_newtable(L); - { - int get_tbl = lua_gettop(L); - - buffer_copy_buffer(b, con->uri.query); - cache_export_get_params(L, get_tbl, b); - buffer_clear(b); - } + cache_export_get_params(L, lua_gettop(L), con->uri.query); lua_setglobal(L, "get"); /* 2 default constants */