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 20:46:43 UTC
svn commit: r1883880 - in /apr/apr/branches/1.7.x: ./ encoding/apr_encode.c
test/testencode.c
Author: ylavic
Date: Fri Nov 27 20:46:43 2020
New Revision: 1883880
URL: http://svn.apache.org/viewvc?rev=1883880&view=rev
Log:
Merge r1883870 from trunk:
apr_decode_base{64,32,16}: stop reading before (not including) NUL byte.
Modified:
apr/apr/branches/1.7.x/ (props changed)
apr/apr/branches/1.7.x/encoding/apr_encode.c
apr/apr/branches/1.7.x/test/testencode.c
Propchange: apr/apr/branches/1.7.x/
------------------------------------------------------------------------------
Merged /apr/apr/trunk:r1883870
Modified: apr/apr/branches/1.7.x/encoding/apr_encode.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/encoding/apr_encode.c?rev=1883880&r1=1883879&r2=1883880&view=diff
==============================================================================
--- apr/apr/branches/1.7.x/encoding/apr_encode.c (original)
+++ apr/apr/branches/1.7.x/encoding/apr_encode.c Fri Nov 27 20:46:43 2020
@@ -394,11 +394,15 @@ APR_DECLARE(apr_status_t) apr_decode_bas
apr_status_t status;
bufin = (const unsigned char *)src;
- while (pr2six[*(bufin++)] < 64 && count)
+ while (count && pr2six[*bufin] < 64) {
count--;
- nprbytes = (bufin - (const unsigned char *)src) - 1;
- while (pr2six[*(bufin++)] > 64 && count)
+ bufin++;
+ }
+ nprbytes = bufin - (const unsigned char *)src;
+ while (count && pr2six[*bufin] > 64) {
count--;
+ bufin++;
+ }
status = flags & APR_ENCODE_RELAXED ? APR_SUCCESS :
count ? APR_BADCH : APR_SUCCESS;
@@ -469,11 +473,15 @@ APR_DECLARE(apr_status_t) apr_decode_bas
apr_status_t status;
bufin = (const unsigned char *)src;
- while (pr2six[*(bufin++)] < 64 && count)
+ while (count && pr2six[*bufin] < 64) {
count--;
- nprbytes = (bufin - (const unsigned char *)src) - 1;
- while (pr2six[*(bufin++)] > 64 && count)
+ bufin++;
+ }
+ nprbytes = bufin - (const unsigned char *)src;
+ while (count && pr2six[*bufin] > 64) {
count--;
+ bufin++;
+ }
status = flags & APR_ENCODE_RELAXED ? APR_SUCCESS :
count ? APR_BADCH : APR_SUCCESS;
@@ -842,11 +850,15 @@ APR_DECLARE(apr_status_t) apr_decode_bas
}
bufin = (const unsigned char *)src;
- while (pr2[*(bufin++)] < 32 && count)
+ while (count && pr2[*bufin] < 32) {
count--;
- nprbytes = (bufin - (const unsigned char *)src) - 1;
- while (pr2[*(bufin++)] > 32 && count)
+ bufin++;
+ }
+ nprbytes = bufin - (const unsigned char *)src;
+ while (count && pr2[*bufin] > 32) {
count--;
+ bufin++;
+ }
status = flags & APR_ENCODE_RELAXED ? APR_SUCCESS :
count ? APR_BADCH : APR_SUCCESS;
@@ -945,11 +957,15 @@ APR_DECLARE(apr_status_t) apr_decode_bas
}
bufin = (const unsigned char *)src;
- while (pr2[*(bufin++)] < 32 && count)
+ while (count && pr2[*bufin] < 32) {
count--;
- nprbytes = (bufin - (const unsigned char *)src) - 1;
- while (pr2[*(bufin++)] > 32 && count)
+ bufin++;
+ }
+ nprbytes = bufin - (const unsigned char *)src;
+ while (count && pr2[*bufin] > 32) {
count--;
+ bufin++;
+ }
status = flags & APR_ENCODE_RELAXED ? APR_SUCCESS :
count ? APR_BADCH : APR_SUCCESS;
@@ -1220,11 +1236,15 @@ APR_DECLARE(apr_status_t) apr_decode_bas
count = slen;
bufin = (const unsigned char *)src;
- while (pr2two[*(bufin++)] != 16 && count)
+ while (count && pr2two[*bufin] != 16) {
count--;
- nprbytes = (bufin - (const unsigned char *)src) - 1;
- while (pr2two[*(bufin++)] > 16 && count)
+ bufin++;
+ }
+ nprbytes = bufin - (const unsigned char *)src;
+ while (count && pr2two[*bufin] > 16) {
count--;
+ bufin++;
+ }
status = flags & APR_ENCODE_RELAXED ? APR_SUCCESS :
count ? APR_BADCH : APR_SUCCESS;
@@ -1310,11 +1330,15 @@ APR_DECLARE(apr_status_t) apr_decode_bas
count = slen;
bufin = (const unsigned char *)src;
- while (pr2two[*(bufin++)] != 16 && count)
+ while (count && pr2two[*bufin] != 16) {
count--;
- nprbytes = (bufin - (const unsigned char *)src) - 1;
- while (pr2two[*(bufin++)] > 16 && count)
+ bufin++;
+ }
+ nprbytes = bufin - (const unsigned char *)src;
+ while (count && pr2two[*bufin] > 16) {
count--;
+ bufin++;
+ }
status = flags & APR_ENCODE_RELAXED ? APR_SUCCESS :
count ? APR_BADCH : APR_SUCCESS;
Modified: apr/apr/branches/1.7.x/test/testencode.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.7.x/test/testencode.c?rev=1883880&r1=1883879&r2=1883880&view=diff
==============================================================================
--- apr/apr/branches/1.7.x/test/testencode.c (original)
+++ apr/apr/branches/1.7.x/test/testencode.c Fri Nov 27 20:46:43 2020
@@ -134,37 +134,42 @@ static void test_decode_base64(abts_case
src = "";
target = "";
dest = apr_pdecode_base64(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
- ABTS_STR_EQUAL(tc, dest, target);
+ ABTS_STR_EQUAL(tc, target, dest);
src = "Zg==";
target = "f";
dest = apr_pdecode_base64(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
- ABTS_STR_EQUAL(tc, dest, target);
+ ABTS_STR_EQUAL(tc, target, dest);
+
+ src = "Zg=";
+ target = "f";
+ dest = apr_pdecode_base64(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
+ ABTS_STR_EQUAL(tc, target, dest);
src = "Zg";
target = "f";
dest = apr_pdecode_base64(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
- ABTS_STR_EQUAL(tc, dest, target);
+ ABTS_STR_EQUAL(tc, target, dest);
src = "Zm8=";
target = "fo";
dest = apr_pdecode_base64(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
- ABTS_STR_EQUAL(tc, dest, target);
+ ABTS_STR_EQUAL(tc, target, dest);
src = "Zm8";
target = "fo";
dest = apr_pdecode_base64(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
- ABTS_STR_EQUAL(tc, dest, target);
+ ABTS_STR_EQUAL(tc, target, dest);
src = "Zm9v";
target = "foo";
dest = apr_pdecode_base64(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
- ABTS_STR_EQUAL(tc, dest, target);
+ ABTS_STR_EQUAL(tc, target, dest);
src = "Zm9v";
target = "foo";
dest = apr_pdecode_base64(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
- ABTS_STR_EQUAL(tc, dest, target);
+ ABTS_STR_EQUAL(tc, target, dest);
apr_pool_destroy(pool);
}
@@ -190,6 +195,11 @@ static void test_decode_base64_binary(ab
udest = apr_pdecode_base64_binary(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
ABTS_INT_EQUAL(tc, len, 1);
+
+ src = "Zg=";
+ udest = apr_pdecode_base64_binary(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);
+ ABTS_ASSERT(tc, "apr_pdecode_base64_binary target!=dest", memcmp(ufoobar, udest, 1) == 0);
+ ABTS_INT_EQUAL(tc, len, 1);
src = "Zg";
udest = apr_pdecode_base64_binary(pool, src, APR_ENCODE_STRING, APR_ENCODE_NONE, &len);