]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
switch_url_encode now takes the full length of the buffer and null-terminates the...
authorStefan Knoblich <stkn@freeswitch.org>
Wed, 21 May 2008 21:31:17 +0000 (21:31 +0000)
committerStefan Knoblich <stkn@freeswitch.org>
Wed, 21 May 2008 21:31:17 +0000 (21:31 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8510 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/applications/mod_voicemail/mod_voicemail.c
src/mod/formats/mod_shout/mod_shout.c
src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c
src/switch_channel.c
src/switch_event.c
src/switch_utils.c

index 84d5d8bb1b7f7e8809c4ae6474dc0a1ecdc304bc..1c3adb5d835ced78b780990f215eef85fa5f8a6e 100644 (file)
@@ -2516,7 +2516,7 @@ static int web_callback(void *pArg, int argc, char **argv, char **columnNames)
                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"
index 46124c8c3b5d912445adbee73027c335c3e5e31b..3dea206d300e19942e0c2899bfce1893686c7c06 100644 (file)
@@ -1017,7 +1017,7 @@ static int web_callback(void *pArg, int argc, char **argv, char **columnNames)
                                    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]);
index d5c550815291b619ffaa4f112cb605a9bd000330..d54a6f1161992301d4a76c5748aa16c35aaac8d6 100644 (file)
@@ -133,7 +133,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
                        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);
index d01591213ebf6b4a08070ba0bd776b6ab9af0104..e7df11d98c396dd97e0cb63c4f601378949d3a4b 100644 (file)
@@ -1877,7 +1877,7 @@ SWITCH_DECLARE(char *) switch_channel_build_param_string(switch_channel_t *chann
 
                        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 @@ SWITCH_DECLARE(char *) switch_channel_build_param_string(switch_channel_t *chann
                                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);
 
                }
index 80552616b5e0298912b24a41b50a0fe3b435676b..579ec467400c13f5631eb539e3c47ab34901f616 100644 (file)
@@ -770,7 +770,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
 
                /* 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 @@ SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, co
 
                        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 @@ SWITCH_DECLARE(char *) switch_event_build_param_string(switch_event_t *event, co
                                        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);
 
                        }
index b59bbfffcb0b5985cc0b3259c6fce847c50ce984..f9ce852a2cb40adaf72f3f2d093cdbc2957ad605 100644 (file)
@@ -1415,15 +1415,18 @@ SWITCH_DECLARE(size_t) switch_url_encode(const char *url, char *buf, size_t len)
                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 @@ SWITCH_DECLARE(size_t) switch_url_encode(const char *url, char *buf, size_t len)
                } else {
                        buf[x++] = *p;
                }
-               if (x == len) {
-                       break;
-               }
        }
+       buf[x] = '\0';
+
        return x;
 }