aboutsummaryrefslogtreecommitdiffstats
path: root/funcs
diff options
context:
space:
mode:
authormnicholson <mnicholson@f38db490-d61c-443f-a65b-d21fe96a405b>2009-11-06 16:26:59 +0000
committermnicholson <mnicholson@f38db490-d61c-443f-a65b-d21fe96a405b>2009-11-06 16:26:59 +0000
commit1681d71ab4dc96b899b026da21a2e7b3bd061a65 (patch)
treeba37194407ec3f324c0bec70dac6bfb41e8e0bc7 /funcs
parent10a2d6e06c07648d0f2881ec501b31918bcc0828 (diff)
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: http://svn.digium.com/svn/asterisk/branches/1.4@228378 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs')
-rw-r--r--funcs/func_base64.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/funcs/func_base64.c b/funcs/func_base64.c
index 463e6dd87..58e618003 100644
--- a/funcs/func_base64.c
+++ b/funcs/func_base64.c
@@ -53,12 +53,19 @@ static int base64_encode(struct ast_channel *chan, char *cmd, char *data,
static int base64_decode(struct ast_channel *chan, char *cmd, char *data,
char *buf, size_t len)
{
+ int decoded_len;
+
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: BASE64_DECODE(<base_64 string>) - 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;
}