From: Matthew Nicholson Date: Fri, 6 Nov 2009 20:42:05 +0000 (+0000) Subject: Merged revisions 228620 via svnmerge from X-Git-Tag: 1.6.0.18-rc2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74770562a77a6c377e20804435634cb433526e70;p=thirdparty%2Fasterisk.git Merged revisions 228620 via svnmerge from https://origsvn.digium.com/svn/asterisk/trunk ................ r228620 | mnicholson | 2009-11-06 13:47:11 -0600 (Fri, 06 Nov 2009) | 15 lines Merged revisions 228378 via svnmerge from https://origsvn.digium.com/svn/asterisk/branches/1.4 ........ r228378 | mnicholson | 2009-11-06 10:26:59 -0600 (Fri, 06 Nov 2009) | 8 lines Properly handle '=' while decoding base64 messages and null terminate strings returned from BASE64_DECODE. (closes issue #15271) Reported by: chappell Patches: base64_fix.patch uploaded by chappell (license 8) Tested by: kobaz ........ ................ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@228651 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/funcs/func_base64.c b/funcs/func_base64.c index 0849e95396..b44e695da9 100644 --- a/funcs/func_base64.c +++ b/funcs/func_base64.c @@ -46,12 +46,19 @@ static int base64_encode(struct ast_channel *chan, const char *cmd, char *data, static int base64_decode(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { + int decoded_len; + if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Syntax: BASE64_DECODE() - missing argument!\n"); return -1; } - ast_base64decode((unsigned char *) buf, data, len); + decoded_len = ast_base64decode((unsigned char *) buf, data, len); + if (decoded_len <= (len - 1)) { /* if not truncated, */ + buf[decoded_len] = '\0'; + } else { + buf[len - 1] = '\0'; + } return 0; } diff --git a/main/utils.c b/main/utils.c index d5d1bb0d2f..f55fe42714 100644 --- a/main/utils.c +++ b/main/utils.c @@ -264,7 +264,7 @@ int ast_base64decode(unsigned char *dst, const char *src, int max) unsigned int byte = 0; unsigned int bits = 0; int incnt = 0; - while (*src && (cnt < max)) { + while(*src && *src != '=' && (cnt < max)) { /* Shift in 6 bits of input */ byte <<= 6; byte |= (b2a[(int)(*src)]) & 0x3f;