From 804c2032a7aa971ca2099be7bab5f49d478a22fd Mon Sep 17 00:00:00 2001 From: Guenter Knauf Date: Sun, 28 Apr 2013 14:59:46 +0000 Subject: [PATCH] Fixed the base64 functions. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1476785 13f79535-47bb-0310-9956-ffa450edef68 --- modules/lua/lua_request.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 5943000bac..b7d6306649 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -719,10 +719,12 @@ static int lua_apr_b64encode(lua_State *L) r = ap_lua_check_request_rec(L, 1); luaL_checktype(L, 2, LUA_TSTRING); plain = lua_tolstring(L, 2, &plain_len); - encoded_len = apr_base64_encode_len(plain_len) + 1; + encoded_len = apr_base64_encode_len(plain_len); if (encoded_len) { encoded = apr_palloc(r->pool, encoded_len); - apr_base64_encode(encoded, plain, plain_len); + encoded_len = apr_base64_encode(encoded, plain, plain_len); + if (encoded_len > 0 && encoded[encoded_len - 1] == '\0') + encoded_len--; lua_pushlstring(L, encoded, encoded_len); return 1; } @@ -738,13 +740,16 @@ static int lua_apr_b64decode(lua_State *L) char *plain; size_t encoded_len, decoded_len; request_rec *r; + r = ap_lua_check_request_rec(L, 1); luaL_checktype(L, 2, LUA_TSTRING); encoded = lua_tolstring(L, 2, &encoded_len); - decoded_len = apr_base64_decode_len(encoded) + 1; + decoded_len = apr_base64_decode_len(encoded); if (decoded_len) { plain = apr_palloc(r->pool, decoded_len); - apr_base64_decode(plain, encoded); + decoded_len = apr_base64_decode(plain, encoded); + if (decoded_len > 0 && plain[decoded_len - 1] == '\0') + decoded_len--; lua_pushlstring(L, plain, decoded_len); return 1; } -- 2.40.0