apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <b...@qqmail.nl>
Subject RE: svn commit: r1780034 - in /apr/apr/trunk: encoding/apr_base64.ctest/testbase64.c
Date Wed, 25 Jan 2017 11:03:03 GMT
Base64 data is always longer than the original data, but now the encoded data is truncated
to the original length by setting the byte after the original length in the encoded data to
’\0’.

I’m surprised this tescase doesn’t catch this problem…

Bert

Sent from Mail for Windows 10

From: dirkx@apache.org
Sent: dinsdag 24 januari 2017 08:46
To: commits@apr.apache.org
Subject: svn commit: r1780034 - in /apr/apr/trunk: encoding/apr_base64.ctest/testbase64.c

Author: dirkx
Date: Tue Jan 24 07:46:10 2017
New Revision: 1780034

URL: http://svn.apache.org/viewvc?rev=1780034&view=rev
Log:
apr_base64_encode_len() already inclues the \0.

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

Modified: apr/apr/trunk/encoding/apr_base64.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/encoding/apr_base64.c?rev=1780034&r1=1780033&r2=1780034&view=diff
==============================================================================
--- apr/apr/trunk/encoding/apr_base64.c (original)
+++ apr/apr/trunk/encoding/apr_base64.c Tue Jan 24 07:46:10 2017
@@ -285,7 +285,7 @@ APR_DECLARE(char *) apr_pbase64_encode(a
     char *encoded;
     int l = strlen(string);
 
-    encoded = (char *) apr_palloc(p, 1 + apr_base64_encode_len(l));
+    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 */
 

Modified: apr/apr/trunk/test/testbase64.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testbase64.c?rev=1780034&r1=1780033&r2=1780034&view=diff
==============================================================================
--- apr/apr/trunk/test/testbase64.c (original)
+++ apr/apr/trunk/test/testbase64.c Tue Jan 24 07:46:10 2017
@@ -69,7 +69,8 @@ static void test_base64(abts_case *tc, v
 
         enc = apr_pbase64_encode(pool, base64_tbl[i].orig);
         ABTS_ASSERT(tc, "base 64 encoded from pool matches expected output",
-                (strcmp(enc, base64_tbl[i].enc) == 0))
+                (strcmp(enc, base64_tbl[i].enc) == 0));
+        ABTS_ASSERT(tc, "base 64 length", strlen(enc) == strlen(base64_tbl[i].enc));
     }
 }
 




Mime
View raw message