httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fua...@apache.org
Subject svn commit: r1476785 - /httpd/httpd/trunk/modules/lua/lua_request.c
Date Sun, 28 Apr 2013 14:59:47 GMT
Author: fuankg
Date: Sun Apr 28 14:59:46 2013
New Revision: 1476785

URL: http://svn.apache.org/r1476785
Log:
Fixed the base64 functions.

Modified:
    httpd/httpd/trunk/modules/lua/lua_request.c

Modified: httpd/httpd/trunk/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1476785&r1=1476784&r2=1476785&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.c Sun Apr 28 14:59:46 2013
@@ -719,10 +719,12 @@ static int lua_apr_b64encode(lua_State *
     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 *
     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;
     }



Mime
View raw message