]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
core uri: Custom uri parsing error when no query parameters
authorKevin Harwell <kharwell@digium.com>
Fri, 6 Jun 2014 20:45:05 +0000 (20:45 +0000)
committerKevin Harwell <kharwell@digium.com>
Fri, 6 Jun 2014 20:45:05 +0000 (20:45 +0000)
If using the custom URI parsing code (not external uriparser lib) and there
was no query parameters the resulting pointer would be NULL and then an
attempt was made to subtract from it.  The pointer is now set to a valid
value if there is no query parameter(s).

Also, in the 'ast_uri_make_host_with_port' function when setting the terminator
on the resulting string it was writing it one past the end of allocated memory.
It now writes the string terminator appropriately.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@415358 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/uri.c
tests/test_websocket_client.c

index 6642d843b2b2bdec44834ce6f84b32b5c8478d61..be1136fe67819bb1faa3de27451170af126d19d5 100644 (file)
@@ -229,6 +229,8 @@ struct ast_uri *ast_uri_parse(const char *uri)
        if ((p = strchr(uri, '?'))) {
                query = p + 1;
                size_query = strlen(query) + 1;
+       } else {
+               p = uri + strlen(uri);
        }
 
        if (!host) {
@@ -313,9 +315,9 @@ char *ast_uri_make_host_with_port(const struct ast_uri *uri)
        if (ast_uri_port(uri)) {
                res[host_size] = ':';
                memcpy(res + host_size + 1,
-                      ast_uri_port(uri), port_size);
+                      ast_uri_port(uri), port_size - 1);
        }
 
-       res[host_size + port_size + 1] = '\0';
+       res[host_size + port_size] = '\0';
        return res;
 }
index e104ed82560332c2c39ae7ebc5000114ec77ad55..726ee1cfccf3f12d216568830c7a018b8c9fb0bf 100644 (file)
@@ -41,7 +41,7 @@ ASTERISK_FILE_VERSION(__FILE__, "")
 #include "asterisk/http_websocket.h"
 
 #define CATEGORY "/res/websocket/"
-#define REMOTE_URL "ws://localhost:8088/ws"
+#define REMOTE_URL "ws://127.0.0.1:8088/ws"
 
 AST_TEST_DEFINE(websocket_client_create_and_connect)
 {