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>
Этот коммит содержится в:
родитель
b5160ce9e0
Коммит
f5bc5147b9
@ -287,7 +287,7 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
|
|||||||
|
|
||||||
/* in base64.c */
|
/* in base64.c */
|
||||||
ssh_buffer base64_to_bin(const char *source);
|
ssh_buffer base64_to_bin(const char *source);
|
||||||
unsigned char *bin_to_base64(const unsigned char *source, int len);
|
uint8_t *bin_to_base64(const uint8_t *source, size_t len);
|
||||||
|
|
||||||
/* gzip.c */
|
/* gzip.c */
|
||||||
int compress_buffer(ssh_session session,ssh_buffer buf);
|
int compress_buffer(ssh_session session,ssh_buffer buf);
|
||||||
|
11
src/base64.c
11
src/base64.c
@ -270,11 +270,11 @@ static void _bin_to_base64(uint8_t *dest,
|
|||||||
*
|
*
|
||||||
* @returns the converted string
|
* @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;
|
uint8_t *base64 = NULL;
|
||||||
unsigned char *ptr;
|
uint8_t *ptr = NULL;
|
||||||
int flen = len + (3 - (len % 3)); /* round to upper 3 multiple */
|
size_t flen = len + (3 - (len % 3)); /* round to upper 3 multiple */
|
||||||
flen = (4 * flen) / 3 + 1;
|
flen = (4 * flen) / 3 + 1;
|
||||||
|
|
||||||
base64 = malloc(flen);
|
base64 = malloc(flen);
|
||||||
@ -286,6 +286,9 @@ unsigned char *bin_to_base64(const unsigned char *source, int len)
|
|||||||
while(len > 0){
|
while(len > 0){
|
||||||
_bin_to_base64(ptr, source, len > 3 ? 3 : len);
|
_bin_to_base64(ptr, source, len > 3 ? 3 : len);
|
||||||
ptr += 4;
|
ptr += 4;
|
||||||
|
if (len < 3) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
source += 3;
|
source += 3;
|
||||||
len -= 3;
|
len -= 3;
|
||||||
}
|
}
|
||||||
|
Загрузка…
Ссылка в новой задаче
Block a user