aboutsummaryrefslogtreecommitdiffstats
path: root/funcs/func_base64.c
diff options
context:
space:
mode:
authormnicholson <mnicholson@f38db490-d61c-443f-a65b-d21fe96a405b>2009-11-06 19:47:11 +0000
committermnicholson <mnicholson@f38db490-d61c-443f-a65b-d21fe96a405b>2009-11-06 19:47:11 +0000
commitc5f892ebece3563c960d20741f1436aa16f0c09e (patch)
treeedcd43288e61877461ed49d2d340ff16f0760267 /funcs/func_base64.c
parent16e3d97832263d09f4de243f636de380bee79b7a (diff)
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: http://svn.digium.com/svn/asterisk/trunk@228620 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs/func_base64.c')
-rw-r--r--funcs/func_base64.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/funcs/func_base64.c b/funcs/func_base64.c
index a68cf9bda..34c6ec6ae 100644
--- a/funcs/func_base64.c
+++ b/funcs/func_base64.c
@@ -79,13 +79,26 @@ static int base64_helper(struct ast_channel *chan, const char *cmd, char *data,
ast_str_update(*str);
}
} else {
+ int decoded_len;
if (buf) {
- ast_base64decode((unsigned char *) buf, data, len);
+ decoded_len = ast_base64decode((unsigned char *) buf, data, len);
+ /* add a terminating null at the end of buf, or at the
+ * end of our decoded string, which ever is less */
+ buf[decoded_len <= (len - 1) ? decoded_len : len - 1] = '\0';
} else {
if (len >= 0) {
ast_str_make_space(str, len ? len : ast_str_strlen(*str) + strlen(data) * 3 / 4 + 2);
}
- ast_base64decode((unsigned char *) ast_str_buffer(*str) + ast_str_strlen(*str), data, ast_str_size(*str) - ast_str_strlen(*str));
+ decoded_len = ast_base64decode((unsigned char *) ast_str_buffer(*str) + ast_str_strlen(*str), data, ast_str_size(*str) - ast_str_strlen(*str));
+ if (len)
+ /* add a terminating null at the end of our
+ * buffer, or at the end of our decoded string,
+ * which ever is less */
+ ast_str_buffer(*str)[decoded_len <= (len - 1) ? decoded_len : len - 1] = '\0';
+ else
+ /* space for the null is allocated above */
+ ast_str_buffer(*str)[decoded_len] = '\0';
+
ast_str_update(*str);
}
}