[asterisk-commits] mnicholson: trunk r301309 - in /trunk: ./ main/utils.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 11 12:55:20 CST 2011


Author: mnicholson
Date: Tue Jan 11 12:55:16 2011
New Revision: 301309

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=301309
Log:
Merged revisions 301308 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r301308 | mnicholson | 2011-01-11 12:51:40 -0600 (Tue, 11 Jan 2011) | 18 lines
  
  Merged revisions 301307 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2
  
  ................
    r301307 | mnicholson | 2011-01-11 12:42:05 -0600 (Tue, 11 Jan 2011) | 11 lines
    
    Merged revisions 301305 via svnmerge from 
    https://origsvn.digium.com/svn/asterisk/branches/1.4
    
    ........
      r301305 | mnicholson | 2011-01-11 12:34:40 -0600 (Tue, 11 Jan 2011) | 4 lines
      
      Prevent buffer overflows in ast_uri_encode()
      
      ABE-2705
    ........
  ................
................

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

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

Modified: trunk/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/utils.c?view=diff&rev=301309&r1=301308&r2=301309
==============================================================================
--- trunk/main/utils.c (original)
+++ trunk/main/utils.c Tue Jan 11 12:55:16 2011
@@ -391,33 +391,32 @@
 char *ast_uri_encode(const char *string, char *outbuf, int buflen, int do_special_char)
 {
 	const char *ptr  = string;	/* Start with the string */
-	char *out = NULL;
-	char *buf = NULL;
+	char *out = outbuf;
 	const char *mark = "-_.!~*'()"; /* no encode set, RFC 2396 section 2.3, RFC 3261 sec 25 */
-	ast_copy_string(outbuf, string, buflen);
-
-	while (*ptr) {
+
+	while (*ptr && out - outbuf < buflen - 1) {
 		if ((const signed char) *ptr < 32 || *ptr == 0x7f || *ptr == '%' ||
 				(do_special_char &&
 				!(*ptr >= '0' && *ptr <= '9') &&      /* num */
 				!(*ptr >= 'A' && *ptr <= 'Z') &&      /* ALPHA */
 				!(*ptr >= 'a' && *ptr <= 'z') &&      /* alpha */
 				!strchr(mark, *ptr))) {               /* mark set */
-
-			/* Oops, we need to start working here */
-			if (!buf) {
-				buf = outbuf;
-				out = buf + (ptr - string) ;	/* Set output ptr */
+			if (out - outbuf >= buflen - 3) {
+				break;
 			}
+
 			out += sprintf(out, "%%%02X", (unsigned char) *ptr);
-		} else if (buf) {
+		} else {
 			*out = *ptr;	/* Continue copying the string */
 			out++;
 		}
 		ptr++;
 	}
-	if (buf)
+
+	if (buflen) {
 		*out = '\0';
+	}
+
 	return outbuf;
 }
 




More information about the asterisk-commits mailing list