Index: main/utils.c
===================================================================
--- main/utils.c	(revision 301307)
+++ main/utils.c	(revision 301308)
@@ -384,33 +384,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;
 }
 

Property changes on: .
___________________________________________________________________
Modified: branch-1.6.2-merged
   - /branches/1.6.2:1-279056,279207,279501,279561,279597,279609,279657,279784,279849,279946,280089,280160,280193,280229,280231,280306,280345,280449,280551,280671,280739,280983,281051,281391,281430,281567,281574,281722,281763,281873,281912,282130,282235,282467,282469,282576,282607,282730,282859,282890,282894,283049,283124,283318,283381,283558,283594,283691,283881,284002,284280,284317,284399,284472,284593-284595,284631,284665,284704,284778,284897,284958,285089,285196,285267,285366,285526,285529,285532,285563,285567,285639,285710,285744,285818,285930,285961,286024,286116-286117,286268,286456,286527,286557,286587,286681,286757,286998,287115,287119,287308,287387,287470,287558,287642,287685,287759,287934,288006,288113,288147,288193,288267,288340,288344,288417,288500,288637,288712,288747,289095,289178,289334,289339,289425,289553,289700,289704,289798,289874,289950,290101,290201,290254,290375,290396,290575,290712,290751,290863,291073,291110-291111,291229,291264,291280,291393,291580,291655,291904,291939,292049,292224,292229,292412,292556,292786,292867,293118,293158,293195-293196,293340,293417,293647,293723,293806,293969,294242,294277,294312,294429,294500,294639,294733,294822,294904,294910,294988,295062,295281,295440,295672,295710,295843,295868,295907,296001,296083,296166,296221,296466,296533,296671,296869,296950,296991,297073,297229,297311,297405,297534,297605,297713,297819,297824,297908,297960,298050,298194,298393,298477,298481,298597,298684,298817,298957,298962,299087,299130,299136,299242,299448,299530,299625,299864,300165,300298,300429,300431,300520,300574,300622,300951,301046,301089,301176,301220
   + /branches/1.6.2:1-279056,279207,279501,279561,279597,279609,279657,279784,279849,279946,280089,280160,280193,280229,280231,280306,280345,280449,280551,280671,280739,280983,281051,281391,281430,281567,281574,281722,281763,281873,281912,282130,282235,282467,282469,282576,282607,282730,282859,282890,282894,283049,283124,283318,283381,283558,283594,283691,283881,284002,284280,284317,284399,284472,284593-284595,284631,284665,284704,284778,284897,284958,285089,285196,285267,285366,285526,285529,285532,285563,285567,285639,285710,285744,285818,285930,285961,286024,286116-286117,286268,286456,286527,286557,286587,286681,286757,286998,287115,287119,287308,287387,287470,287558,287642,287685,287759,287934,288006,288113,288147,288193,288267,288340,288344,288417,288500,288637,288712,288747,289095,289178,289334,289339,289425,289553,289700,289704,289798,289874,289950,290101,290201,290254,290375,290396,290575,290712,290751,290863,291073,291110-291111,291229,291264,291280,291393,291580,291655,291904,291939,292049,292224,292229,292412,292556,292786,292867,293118,293158,293195-293196,293340,293417,293647,293723,293806,293969,294242,294277,294312,294429,294500,294639,294733,294822,294904,294910,294988,295062,295281,295440,295672,295710,295843,295868,295907,296001,296083,296166,296221,296466,296533,296671,296869,296950,296991,297073,297229,297311,297405,297534,297605,297713,297819,297824,297908,297960,298050,298194,298393,298477,298481,298597,298684,298817,298957,298962,299087,299130,299136,299242,299448,299530,299625,299864,300165,300298,300429,300431,300520,300574,300622,300951,301046,301089,301176,301220,301307

