[asterisk-commits] mnicholson: trunk r228620 - in /trunk: ./ funcs/func_base64.c main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 6 13:47:15 CST 2009


Author: mnicholson
Date: Fri Nov  6 13:47:11 2009
New Revision: 228620

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=228620
Log:
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
........

Modified:
    trunk/   (props changed)
    trunk/funcs/func_base64.c
    trunk/main/utils.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/funcs/func_base64.c
URL: http://svnview.digium.com/svn/asterisk/trunk/funcs/func_base64.c?view=diff&rev=228620&r1=228619&r2=228620
==============================================================================
--- trunk/funcs/func_base64.c (original)
+++ trunk/funcs/func_base64.c Fri Nov  6 13:47:11 2009
@@ -79,13 +79,26 @@
 			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);
 		}
 	}

Modified: trunk/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/utils.c?view=diff&rev=228620&r1=228619&r2=228620
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Fri Nov  6 13:47:11 2009
@@ -267,7 +267,7 @@
 	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;




More information about the asterisk-commits mailing list