You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by yl...@apache.org on 2020/11/27 15:23:31 UTC

svn commit: r1883861 - /apr/apr/trunk/encoding/apr_base64.c

Author: ylavic
Date: Fri Nov 27 15:23:31 2020
New Revision: 1883861

URL: http://svn.apache.org/viewvc?rev=1883861&view=rev
Log:
apr_base64: avoid double NUL termination in apr_pbase64_{encode,decode}()

Since apr_base64_{encode,decode}() already NUL terminate the result, it
needs not be done in apr_pbase64_{encode,decode}().

The NUL byte is also included in apr_base64_decode_len(), so no need to
reserve an extra one in apr_pbase64_decode() etiher.

Modified:
    apr/apr/trunk/encoding/apr_base64.c

Modified: apr/apr/trunk/encoding/apr_base64.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/encoding/apr_base64.c?rev=1883861&r1=1883860&r2=1883861&view=diff
==============================================================================
--- apr/apr/trunk/encoding/apr_base64.c (original)
+++ apr/apr/trunk/encoding/apr_base64.c Fri Nov 27 15:23:31 2020
@@ -191,11 +191,9 @@ APR_DECLARE(int) apr_base64_decode_binar
 APR_DECLARE(char *) apr_pbase64_decode(apr_pool_t *p, const char *bufcoded)
 {
     char *decoded;
-    int l;
 
-    decoded = (char *) apr_palloc(p, 1 + apr_base64_decode_len(bufcoded));
-    l = apr_base64_decode(decoded, bufcoded);
-    decoded[l] = '\0'; /* make binary sequence into string */
+    decoded = (char *) apr_palloc(p, apr_base64_decode_len(bufcoded));
+    apr_base64_decode(decoded, bufcoded);
 
     return decoded;
 }
@@ -286,8 +284,7 @@ APR_DECLARE(char *) apr_pbase64_encode(a
     int l = strlen(string);
 
     encoded = (char *) apr_palloc(p, apr_base64_encode_len(l));
-    l = apr_base64_encode(encoded, string, l);
-    encoded[l] = '\0'; /* make binary sequence into string */
+    apr_base64_encode(encoded, string, l);
 
     return encoded;
 }