[svn-commits] mnicholson: branch 1.6.1 r302142 - /branches/1.6.1/main/utils.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jan 17 12:51:12 CST 2011


Author: mnicholson
Date: Mon Jan 17 12:51:07 2011
New Revision: 302142

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=302142
Log:
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:
    branches/1.6.1/main/utils.c

Modified: branches/1.6.1/main/utils.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.1/main/utils.c?view=diff&rev=302142&r1=302141&r2=302142
==============================================================================
--- branches/1.6.1/main/utils.c (original)
+++ branches/1.6.1/main/utils.c Mon Jan 17 12:51:07 2011
@@ -385,28 +385,27 @@
 	char *reserved = ";/?:@&=+$,# ";	/* Reserved chars */
 
  	const char *ptr  = string;	/* Start with the string */
-	char *out = NULL;
-	char *buf = NULL;
-
-	ast_copy_string(outbuf, string, buflen);
-
-	/* If there's no characters to convert, just go through and don't do anything */
-	while (*ptr) {
+	char *out = outbuf;
+
+	/* If there's no characters to convert, just go through and copy the string */
+	while (*ptr && out - outbuf < buflen - 1) {
 		if ((*ptr < 32) || (doreserved && strchr(reserved, *ptr))) {
-			/* 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) {
-			*out = *ptr;	/* Continue copying the string */
+		} else {
+			*out = *ptr;	/* copy the character */
 			out++;
-		} 
+		}
 		ptr++;
 	}
-	if (buf)
+
+	if (buflen) {
 		*out = '\0';
+	}
+
 	return outbuf;
 }
 




More information about the svn-commits mailing list