axis-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nadira...@apache.org
Subject svn commit: r949655 - /axis/axis2/c/core/trunk/util/src/url.c
Date Mon, 31 May 2010 02:59:39 GMT
Author: nadiramra
Date: Mon May 31 02:59:39 2010
New Revision: 949655

URL: http://svn.apache.org/viewvc?rev=949655&view=rev
Log:
AXIS2C-1414 Error in length computing in util/url.c

Modified:
    axis/axis2/c/core/trunk/util/src/url.c

Modified: axis/axis2/c/core/trunk/util/src/url.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/util/src/url.c?rev=949655&r1=949654&r2=949655&view=diff
==============================================================================
--- axis/axis2/c/core/trunk/util/src/url.c (original)
+++ axis/axis2/c/core/trunk/util/src/url.c Mon May 31 02:59:39 2010
@@ -311,42 +311,40 @@ axutil_url_to_external_form(
 {
     axis2_char_t *external_form = NULL;
     axis2_ssize_t len = 0;
-    axis2_char_t port_str[8];
+    axis2_char_t port_str[11];
     axis2_bool_t print_port = AXIS2_FALSE;
     AXIS2_PARAM_CHECK(env->error, url, NULL);
 
     if(!url->protocol)
-    {
         return NULL;
-    }
 
     if(url->port != 0 && url->port != axutil_uri_port_of_scheme(url->protocol))
     {
         print_port = AXIS2_TRUE;
         sprintf(port_str, "%d", url->port);
+        len += axutil_strlen(port_str) + 1; /* +1 is for ':' */
     }
 
     len = axutil_strlen(url->protocol) + 6;
+
     if(url->host)
-    {
         len += axutil_strlen(url->host);
-    }
+
     if(url->path)
-    {
         len += axutil_strlen(url->path);
-    }
+
     if(url->query)
-    {
         len += axutil_strlen(url->query);
-    }
-    if(print_port)
-    {
-        len += axutil_strlen(port_str) + 1;
-    }
-    external_form = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len);
-    sprintf(external_form, "%s://%s%s%s%s%s", url->protocol, (url->host) ? url->host
: "",
-        (print_port) ? ":" : "", (print_port) ? port_str : "", (url->path) ? url->path
: "",
-        (url->query) ? url->query : "");
+
+    external_form = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len + 1);
+    sprintf(external_form, "%s://%s%s%s%s%s",
+            url->protocol,
+            (url->host) ? url->host : "",
+            (print_port) ? ":" : "",
+            (print_port) ? port_str : "",
+            (url->path) ? url->path : "",
+            (url->query) ? url->query : "");
+
     return external_form;
 }
 
@@ -357,12 +355,14 @@ axutil_url_set_protocol(
     axis2_char_t *protocol)
 {
     AXIS2_PARAM_CHECK(env->error, protocol, AXIS2_FAILURE);
+
     if(url->protocol)
     {
         AXIS2_FREE(env->allocator, url->protocol);
         url->protocol = NULL;
     }
     url->protocol = axutil_strdup(env, protocol);
+
     return AXIS2_SUCCESS;
 }
 
@@ -380,9 +380,6 @@ axutil_url_set_host(
     const axutil_env_t *env,
     axis2_char_t *host)
 {
-    axis2_ssize_t len = 0;
-    axis2_char_t port_str[8];
-    axis2_bool_t print_port = AXIS2_FALSE;
     AXIS2_PARAM_CHECK(env->error, host, AXIS2_FAILURE);
 
     if(url->host)
@@ -390,23 +387,35 @@ axutil_url_set_host(
         AXIS2_FREE(env->allocator, url->host);
     }
     url->host = axutil_strdup(env, host);
+
     if(url->server)
     {
         AXIS2_FREE(env->allocator, url->server);
+        url->server = NULL;
     }
-    if(!url->host)
-    {
-        return AXIS2_SUCCESS;
-    }
-    len += axutil_strlen(url->host);
-    if(url->port != 0 && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol)))
+
+    if(url->host)
     {
-        print_port = AXIS2_TRUE;
-        sprintf(port_str, "%d", url->port);
-        len += axutil_strlen(port_str) + 1;
+        axis2_ssize_t len;
+        axis2_char_t port_str[11];
+        axis2_bool_t print_port = AXIS2_FALSE;
+
+        len = axutil_strlen(url->host);
+        if(url->port != 0
+                && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol)))
+        {
+            print_port = AXIS2_TRUE;
+            sprintf(port_str, "%d", url->port);
+            len += axutil_strlen(port_str) + 1; /* +1 is for ':' */
+        }
+
+        url->server = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len + 1);
+        sprintf(url->server, "%s%s%s",
+                url->host,
+                (print_port) ? ":" : "",
+                (print_port) ? port_str : "");
     }
-    url->server = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len);
-    sprintf(url->server, "%s%s%s", url->host, (print_port) ? ":" : "", (print_port)
? port_str : "");
+
     return AXIS2_SUCCESS;
 }
 
@@ -428,31 +437,25 @@ axutil_url_set_server(
     axis2_char_t *port_str = NULL;
     AXIS2_PARAM_CHECK(env->error, server, AXIS2_FAILURE);
 
-    temp = axutil_strdup(env, server);
-    if(temp && *temp == ':')
-    {
-        AXIS2_FREE(env->allocator, temp);
+    if(*server == ':' || strchr(server, '/'))
         return AXIS2_FAILURE;
-    }
-
-    if(strchr(temp, '/'))
-    {
-        AXIS2_FREE(env->allocator, temp);
-        return AXIS2_FAILURE;
-    }
 
     if(url->server)
     {
         AXIS2_FREE(env->allocator, url->server);
+        url->server = NULL;
     }
+
     if(url->host)
     {
         AXIS2_FREE(env->allocator, url->host);
+        url->host = NULL;
     }
-    url->port = 0;
 
+    url->port   = 0;
     url->server = axutil_strdup(env, server);
 
+    temp = axutil_strdup(env, server);
     port_str = strchr(temp, ':');
     if(port_str)
     {
@@ -462,6 +465,7 @@ axutil_url_set_server(
 
     url->host = axutil_strdup(env, temp);
     AXIS2_FREE(env->allocator, temp);
+
     return AXIS2_SUCCESS;
 }
 
@@ -471,13 +475,11 @@ axutil_url_get_server(
     const axutil_env_t *env)
 {
     axis2_ssize_t len = 0;
-    axis2_char_t port_str[8];
+    axis2_char_t port_str[11];
     axis2_bool_t print_port = AXIS2_FALSE;
 
     if(!url->server && !url->host)
-    {
         return NULL;
-    }
     else if(!url->host)
     {
         AXIS2_FREE(env->allocator, url->server);
@@ -485,18 +487,23 @@ axutil_url_get_server(
         return NULL;
     }
     else if(url->server)
-    {
         return url->server;
-    }
+
     len += axutil_strlen(url->host);
-    if(url->port != 0 && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol)))
+    if(url->port != 0
+            && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol)))
     {
         print_port = AXIS2_TRUE;
         sprintf(port_str, "%d", url->port);
         len += axutil_strlen(port_str) + 1; /* +1 is for ':' */
     }
+
     url->server = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len + 1); /* +1 is for
'/0' */
-    sprintf(url->server, "%s%s%s", url->host, (print_port) ? ":" : "", (print_port)
? port_str : "");
+    sprintf(url->server, "%s%s%s",
+            url->host,
+            (print_port) ? ":" : "",
+            (print_port) ? port_str : "");
+
     return url->server;
 }
 
@@ -507,30 +514,37 @@ axutil_url_set_port(
     int port)
 {
     axis2_ssize_t len = 0;
-    axis2_char_t port_str[8];
+    axis2_char_t port_str[11];
     axis2_bool_t print_port = AXIS2_FALSE;
+
     if(url->port == port)
-    {
         return AXIS2_SUCCESS;
-    }
+
     url->port = port;
     if(url->server)
     {
         AXIS2_FREE(env->allocator, url->server);
+        url->server = NULL;
     }
-    if(!url->host)
-    {
-        return AXIS2_SUCCESS;
-    }
-    len += axutil_strlen(url->host);
-    if(url->port != 0 && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol)))
+
+    if(url->host)
     {
-        print_port = AXIS2_TRUE;
-        sprintf(port_str, "%d", url->port);
-        len += axutil_strlen(port_str) + 1;
+        len += axutil_strlen(url->host);
+        if(url->port != 0
+                && (!url->protocol || url->port != axutil_uri_port_of_scheme(url->protocol)))
+        {
+            print_port = AXIS2_TRUE;
+            sprintf(port_str, "%d", url->port);
+            len += axutil_strlen(port_str) + 1; /* +1 is for ':' */
+        }
+
+        url->server = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len + 1);
+        sprintf(url->server, "%s%s%s",
+                url->host,
+                (print_port) ? ":" : "",
+                (print_port) ? port_str : "");
     }
-    url->server = (axis2_char_t *)AXIS2_MALLOC(env->allocator, len);
-    sprintf(url->server, "%s%s%s", url->host, (print_port) ? ":" : "", (print_port)
? port_str : "");
+
     return AXIS2_SUCCESS;
 }
 
@@ -543,6 +557,7 @@ axutil_url_get_port(
     {
         return axutil_uri_port_of_scheme(url->protocol);
     }
+
     return url->port;
 }
 
@@ -556,6 +571,7 @@ axutil_url_set_path(
     if(url->path)
     {
         AXIS2_FREE(env->allocator, url->path);
+        url->path = NULL;
     }
     url->path = axutil_strdup(env, path);
     return AXIS2_SUCCESS;



Mime
View raw message