]> granicus.if.org Git - transmission/commitdiff
(trunk libT) Use tr_strndup() instead of tr_strdup() in tr_urlParse() to avoid a...
authorJordan Lee <jordan@transmissionbt.com>
Tue, 5 Apr 2011 00:55:09 +0000 (00:55 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Tue, 5 Apr 2011 00:55:09 +0000 (00:55 +0000)
libtransmission/utils.c

index 483a5d26ae45eb8739a328b586517fd442e0af63..1e12a1daf3bc963af410e283312546501a54bc36 100644 (file)
@@ -1010,8 +1010,10 @@ tr_urlParse( const char * url_in,
     int          n;
     char *       tmp;
     char *       pch;
-    const char * protocol = NULL;
+    size_t       host_len;
+    size_t       protocol_len;
     const char * host = NULL;
+    const char * protocol = NULL;
     const char * path = NULL;
 
     tmp = tr_strndup( url_in, len );
@@ -1019,12 +1021,14 @@ tr_urlParse( const char * url_in,
     {
         *pch = '\0';
         protocol = tmp;
+        protocol_len = pch - protocol;
         pch += 3;
 /*fprintf( stderr, "protocol is [%s]... what's left is [%s]\n", protocol, pch);*/
         if( ( n = strcspn( pch, ":/" ) ) )
         {
             const int havePort = pch[n] == ':';
             host = pch;
+            host_len = n;
             pch += n;
             *pch++ = '\0';
 /*fprintf( stderr, "host is [%s]... what's left is [%s]\n", host, pch );*/
@@ -1053,10 +1057,10 @@ tr_urlParse( const char * url_in,
 
     if( !err )
     {
-        if( setme_protocol ) *setme_protocol = tr_strdup( protocol );
+        if( setme_protocol ) *setme_protocol = tr_strndup( protocol, protocol_len );
 
         if( setme_host ){ ( (char*)host )[-3] = ':'; *setme_host =
-                              tr_strdup( host ); }
+                              tr_strndup( host, host_len ); }
         if( setme_path ){ if( path[0] == '/' ) *setme_path = tr_strdup( path );
                           else { ( (char*)path )[-1] = '/'; *setme_path = tr_strdup( path - 1 ); } }
         if( setme_port ) *setme_port = port;