aboutsummaryrefslogtreecommitdiff
path: root/src/base64.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2019-10-31 16:32:35 +0100
committerAndreas Schneider <asn@cryptomilk.org>2019-12-09 16:08:03 +0100
commitf5bc5147b972b7fc27b38c2ecb290d8cf1a2dd74 (patch)
tree398185a41ab53f70711841044d6d3efffd8b4fc7 /src/base64.c
parentb5160ce9e0cf44033bd7dd66bd1e3802651fc341 (diff)
downloadlibssh-f5bc5147b972b7fc27b38c2ecb290d8cf1a2dd74.tar.gz
libssh-f5bc5147b972b7fc27b38c2ecb290d8cf1a2dd74.tar.xz
libssh-f5bc5147b972b7fc27b38c2ecb290d8cf1a2dd74.zip
base64: Fix size types of bin_to_base64()
Fixes T188 Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Diffstat (limited to 'src/base64.c')
-rw-r--r--src/base64.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/base64.c b/src/base64.c
index f019ef76..c771b831 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -270,11 +270,11 @@ static void _bin_to_base64(uint8_t *dest,
*
* @returns the converted string
*/
-unsigned char *bin_to_base64(const unsigned char *source, int len)
+uint8_t *bin_to_base64(const uint8_t *source, size_t len)
{
- unsigned char *base64;
- unsigned char *ptr;
- int flen = len + (3 - (len % 3)); /* round to upper 3 multiple */
+ uint8_t *base64 = NULL;
+ uint8_t *ptr = NULL;
+ size_t flen = len + (3 - (len % 3)); /* round to upper 3 multiple */
flen = (4 * flen) / 3 + 1;
base64 = malloc(flen);
@@ -286,6 +286,9 @@ unsigned char *bin_to_base64(const unsigned char *source, int len)
while(len > 0){
_bin_to_base64(ptr, source, len > 3 ? 3 : len);
ptr += 4;
+ if (len < 3) {
+ break;
+ }
source += 3;
len -= 3;
}