diff options
author | Yann Ylavic <ylavic@apache.org> | 2020-11-27 20:46:43 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2020-11-27 20:46:43 +0000 |
commit | 1c4931097d53c5056e4010ec4e5d0f3bf34d06e5 (patch) | |
tree | ccc90715080cf78112cdbc193ff8b86eea9279b9 /encoding/apr_encode.c | |
parent | 31cf18582df6c467e12d59bf3850427a7f6a5a30 (diff) | |
download | apr-1c4931097d53c5056e4010ec4e5d0f3bf34d06e5.tar.gz |
Merge r1883870 from trunk:
apr_decode_base{64,32,16}: stop reading before (not including) NUL byte.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.7.x@1883880 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'encoding/apr_encode.c')
-rw-r--r-- | encoding/apr_encode.c | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/encoding/apr_encode.c b/encoding/apr_encode.c index b3278c7fd..bc2dc5437 100644 --- a/encoding/apr_encode.c +++ b/encoding/apr_encode.c @@ -394,11 +394,15 @@ APR_DECLARE(apr_status_t) apr_decode_base64(char *dest, const char *src, 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_base64_binary(unsigned char *dest, 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_base32(char *dest, const char *src, } 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_base32_binary(unsigned char *dest, } 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_base16(char *dest, 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_base16_binary(unsigned char *dest, 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; |