From: Daniel Gruno Date: Wed, 1 Aug 2012 07:28:22 +0000 (+0000) Subject: mod_lua: X-Git-Tag: 2.5.0-alpha~6546 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=238af542a37197101aa9676466d29e101d37954b;p=thirdparty%2Fapache%2Fhttpd.git mod_lua: Clean up style use apr_pstrcat instead of apr_psprintf fix a bug that was causing bad string interpolations. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1367875 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c index 3b0631c5c46..460f8e2d371 100644 --- a/modules/lua/mod_lua.c +++ b/modules/lua/mod_lua.c @@ -183,18 +183,23 @@ static const char* ap_lua_interpolate_string(apr_pool_t* pool, const char* strin if (x-y > 0) { stringBetween = apr_pstrndup(pool, string+y, x-y); } - else stringBetween = ""; - int v = atoi(apr_pstrndup(pool,string+x+1, 1)); - ret = apr_psprintf(pool, "%s%s%s", ret, stringBetween, values[v]); - y = ++x; + else { + stringBetween = ""; + } + int v = *(string+x+1) - '0'; + ret = apr_pstrcat(pool, ret, stringBetween, values[v], NULL); + y = ++x+1; } } if (x-y > 0 && y > 0) { - stringBetween = apr_pstrndup(pool, string+y+1, x-y); - ret = apr_psprintf(pool, "%s%s", ret, stringBetween); + stringBetween = apr_pstrndup(pool, string+y, x-y); + ret = apr_pstrcat(pool, ret, stringBetween, NULL); + } + /* If no replacement was made, just return the original string */ + else if (y==0) { + return string; } - else if (y==0) return string; /* If no replacement was made, just return the original str. */ return ret; } @@ -362,7 +367,6 @@ static int lua_map_handler(request_rec *r) hook_spec->bytecode_len, function_name, "mapped handler"); - L = ap_lua_get_lua_state(pool, spec, r); if (!L) {