[Freeswitch-svn] [commit] r8510 - in freeswitch/trunk/src: . mod/applications/mod_voicemail mod/formats/mod_shout mod/xml_int/mod_xml_cdr

Freeswitch SVN stkn at freeswitch.org
Wed May 21 17:31:18 EDT 2008


Author: stkn
Date: Wed May 21 17:31:17 2008
New Revision: 8510

Modified:
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c
   freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
   freeswitch/trunk/src/switch_channel.c
   freeswitch/trunk/src/switch_event.c
   freeswitch/trunk/src/switch_utils.c

Log:
switch_url_encode now takes the full length of the buffer and null-terminates the string properly (Klocwork #1030)

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Wed May 21 17:31:17 2008
@@ -2516,7 +2516,7 @@
 		strcmp(argv[10], URGENT_FLAG_STRING) ? "normal" : "urgent", create_date, heard, duration_str);
 
 	switch_snprintf(title_b4, sizeof(title_b4), "%s <%s> %s", argv[5], argv[6], rss_date);
-	switch_url_encode(title_b4, title_aft, sizeof(title_aft)-1);
+	switch_url_encode(title_b4, title_aft, sizeof(title_aft));
 
 	holder->stream->write_function(holder->stream,
 		"<br><object width=550 height=15 \n"

Modified: freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c	(original)
+++ freeswitch/trunk/src/mod/formats/mod_shout/mod_shout.c	Wed May 21 17:31:17 2008
@@ -1017,7 +1017,7 @@
                                    argv[1], argv[4], argv[5], argv[7], argv[8] ? argv[8] : "N/A", argv[9] ? argv[9] : "N/A", argv[10], argv[11]);
     
     snprintf(title_b4, sizeof(title_b4), "%s <%s>", argv[4], argv[5]);
-    switch_url_encode(title_b4, title_aft, sizeof(title_aft)-1);
+    switch_url_encode(title_b4, title_aft, sizeof(title_aft));
 
     mp3 = switch_mprintf("http://%s:%s%s/mp3/%s/%s.mp3", holder->host, holder->port, holder->uri, argv[0], argv[5]);
     m3u = switch_mprintf("http://%s:%s%s/m3u/mp3/%s/%s.mp3.m3u", holder->host, holder->port, holder->uri, argv[0], argv[5]);

Modified: freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
==============================================================================
--- freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	(original)
+++ freeswitch/trunk/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c	Wed May 21 17:31:17 2008
@@ -133,7 +133,7 @@
 			memset(xml_text_escaped, 0, need_bytes);
 			if (globals.encode == 1) {
 				headers = curl_slist_append(headers, "Content-Type: application/x-www-form-urlencoded");
-				switch_url_encode(xml_text, xml_text_escaped, need_bytes - 1);
+				switch_url_encode(xml_text, xml_text_escaped, need_bytes);
 			} else {
 				headers = curl_slist_append(headers, "Content-Type: application/x-www-form-base64-encoded");
 				switch_b64_encode((unsigned char *)xml_text, need_bytes / 3, (unsigned char *)xml_text_escaped, need_bytes);

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Wed May 21 17:31:17 2008
@@ -1877,7 +1877,7 @@
 
 			encode_buf = tmp;
 		}
-		switch_url_encode(prof[x], encode_buf, encode_len - 1);
+		switch_url_encode(prof[x], encode_buf, encode_len);
 		stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
 	}
 
@@ -1897,7 +1897,7 @@
 				encode_buf = tmp;
 			}
 
-			switch_url_encode((char *) val, encode_buf, encode_len - 1);
+			switch_url_encode((char *) val, encode_buf, encode_len);
 			stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
 
 		}

Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c	(original)
+++ freeswitch/trunk/src/switch_event.c	Wed May 21 17:31:17 2008
@@ -770,7 +770,7 @@
 
 		/* handle any bad things in the string like newlines : etc that screw up the serialized format */
 		if (encode) {
-			switch_url_encode(hp->value, encode_buf, encode_len - 1);
+			switch_url_encode(hp->value, encode_buf, encode_len);
 		} else {
 			switch_snprintf(encode_buf, encode_len, "[%s]", hp->value);
 		}
@@ -1319,7 +1319,7 @@
 
 			encode_buf = tmp;
 		}
-		switch_url_encode(prof[x], encode_buf, encode_len - 1);
+		switch_url_encode(prof[x], encode_buf, encode_len);
 		stream.write_function(&stream, "%s=%s&", prof_names[x], encode_buf);
 	}
 
@@ -1348,7 +1348,7 @@
 					encode_buf = tmp;
 				}
 
-				switch_url_encode((char *) val, encode_buf, encode_len - 1);
+				switch_url_encode((char *) val, encode_buf, encode_len);
 				stream.write_function(&stream, "%s=%s&", (char *) var, encode_buf);
 
 			}

Modified: freeswitch/trunk/src/switch_utils.c
==============================================================================
--- freeswitch/trunk/src/switch_utils.c	(original)
+++ freeswitch/trunk/src/switch_utils.c	Wed May 21 17:31:17 2008
@@ -1415,15 +1415,18 @@
 		return 0;
 	}
 
-	memset(buf, 0, len);
-
 	if (!url) {
 		return 0;
 	}
 
+	len--;
+
 	for (p = url; *p; p++) {
+		if (x >= len) {
+			break;
+		}
 		if (*p < ' ' || *p > '~' || strchr(urlunsafe, *p)) {
-			if ((x + 3) > len) {
+			if ((x + 3) >= len) {
 				break;
 			}
 			buf[x++] = '%';
@@ -1432,10 +1435,9 @@
 		} else {
 			buf[x++] = *p;
 		}
-		if (x == len) {
-			break;
-		}
 	}
+	buf[x] = '\0';
+
 	return x;
 }
 



More information about the Freeswitch-svn mailing list