Index: main/utils.c
===================================================================
--- main/utils.c	(revision 301306)
+++ main/utils.c	(revision 301307)
@@ -386,28 +386,27 @@
 	char *reserved = ";/?:@&=+$,# ";	/* Reserved chars */
 
  	const char *ptr  = string;	/* Start with the string */
-	char *out = NULL;
-	char *buf = NULL;
+	char *out = outbuf;
 
-	ast_copy_string(outbuf, string, buflen);
-
-	/* If there's no characters to convert, just go through and don't do anything */
-	while (*ptr) {
+	/* 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;
 }
 

Property changes on: .
___________________________________________________________________
Modified: branch-1.4-merged
   - /branches/1.4:1-279056,279206,279945,280088,280341,280448,280811,280982,281390,281566,281762,281819,281911,282129,282430,282729,282893,283048,283123,283380,283690,283880,283960,284316,284393,284478,284703,284777,284881,285088,285194,285266,285365,285566,285638,285742,285817,285889,286023,286059,286113-286114,286222,286267,286679,286756,286941,287114,287118,287197,287307,287386,287469,287555,287758,287933,288005,288112,288192,288265-288266,288339,288343,288416,288499,288636,288746,289094,289177,289338,289424,289500,289699,289703,289797,289873,289949,290100,290177,290323,290392,290750,290862,291109,291263,291392,291577,291643,291938,292222-292223,292411,292866,293004,293194,293339,293416,293639,293722,293805,293968,294384,294688,294821,294903,295026,295280,295628,295790,295906,296000,296082,296165,296213,296309,296670,296868,296990,297072,297185,297228,297310,297404,297603,297689,297818,297823,297959,298193,298345,298392,298480,298596,298683,298905,299194-299220,299624,300216,300428,300621,300918
   + /branches/1.4:1-279056,279206,279945,280088,280341,280448,280811,280982,281390,281566,281762,281819,281911,282129,282430,282729,282893,283048,283123,283380,283690,283880,283960,284316,284393,284478,284703,284777,284881,285088,285194,285266,285365,285566,285638,285742,285817,285889,286023,286059,286113-286114,286222,286267,286679,286756,286941,287114,287118,287197,287307,287386,287469,287555,287758,287933,288005,288112,288192,288265-288266,288339,288343,288416,288499,288636,288746,289094,289177,289338,289424,289500,289699,289703,289797,289873,289949,290100,290177,290323,290392,290750,290862,291109,291263,291392,291577,291643,291938,292222-292223,292411,292866,293004,293194,293339,293416,293639,293722,293805,293968,294384,294688,294821,294903,295026,295280,295628,295790,295906,296000,296082,296165,296213,296309,296670,296868,296990,297072,297185,297228,297310,297404,297603,297689,297818,297823,297959,298193,298345,298392,298480,298596,298683,298905,299194-299220,299624,300216,300428,300621,300918,301305


