]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
conn->ip_addr MUST NOT be used on re-used connections
authorDaniel Stenberg <daniel@haxx.se>
Sat, 29 Jan 2005 13:07:16 +0000 (13:07 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 29 Jan 2005 13:07:16 +0000 (13:07 +0000)
CHANGES
lib/connect.c
lib/connect.h
lib/ftp.c
lib/url.c
lib/urldata.h

diff --git a/CHANGES b/CHANGES
index 42317ac858f9fb2549d10dcb04c7af25a7080f2b..99f5ee58eb5671a4d0f140c622a65ec541355075 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,9 @@
                                   Changelog
 
 Daniel (29 January 2005)
+- Adjusted the KNOWN_BUGS #17 fix a bit more since the FTP code also did some
+  bad assumptions.
+
 - multi interface: when a request is denied due to "Maximum redirects
   followed" libcurl leaked the last Location: URL.
 
index 5cd4c06561080130ab8c72e9296aa6980c3b8a1c..104be2d426ea1fa3be41618e41115b20f6cad17f 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -429,6 +429,25 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
   return rc;
 }
 
+CURLcode Curl_store_ip_addr(struct connectdata *conn)
+{
+  char addrbuf[256];
+  Curl_printable_address(conn->ip_addr, addrbuf, sizeof(addrbuf));
+
+  /* save the string */
+  Curl_safefree(conn->ip_addr_str);
+  conn->ip_addr_str = strdup(addrbuf);
+  if(!conn->ip_addr_str)
+    return CURLE_OUT_OF_MEMORY; /* FAIL */
+
+#ifdef PF_INET6
+  if(conn->ip_addr->ai_family == PF_INET6)
+    conn->bits.ipv6 = TRUE;
+#endif
+
+  return CURLE_OK;
+}
+
 /* Used within the multi interface. Try next IP address, return TRUE if no
    more address exists */
 static bool trynextip(struct connectdata *conn,
@@ -450,6 +469,8 @@ static bool trynextip(struct connectdata *conn,
       /* store the new socket descriptor */
       conn->sock[sockindex] = sockfd;
       conn->ip_addr = ai;
+
+      Curl_store_ip_addr(conn);
       return FALSE;
     }
     ai = ai->ai_next;
index d39495cfc75c48fc3ce2c35096da7e9f14019915..50a9e346400d648251be5ad63f5307a6a3506308 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -39,6 +39,8 @@ CURLcode Curl_connecthost(struct connectdata *conn,
 
 int Curl_ourerrno(void);
 
+CURLcode Curl_store_ip_addr(struct connectdata *conn);
+
 #define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
 
 #endif
index e5ad8bde11aff5507a52726b2e90ae5ddd0170b2..e6d2cdfae15053a2dba1e5fec80e6c153a10af39 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -1226,12 +1226,10 @@ CURLcode ftp_use_port(struct connectdata *conn)
   }
 
 #ifdef PF_INET6
-  if(!conn->bits.ftp_use_eprt &&
-     (conn->ip_addr->ai_family == PF_INET6)) {
+  if(!conn->bits.ftp_use_eprt && conn->bits.ipv6)
     /* EPRT is disabled but we are connected to a IPv6 host, so we ignore the
-       request! */
+       request and enable EPRT again! */
     conn->bits.ftp_use_eprt = TRUE;
-  }
 #endif
 
   for (fcmd = EPRT; fcmd != DONE; fcmd++) {
@@ -1563,12 +1561,10 @@ CURLcode ftp_use_pasv(struct connectdata *conn,
   char newhost[NEWHOST_BUFSIZE];
 
 #ifdef PF_INET6
-  if(!conn->bits.ftp_use_epsv &&
-     (conn->ip_addr->ai_family == PF_INET6)) {
+  if(!conn->bits.ftp_use_epsv && conn->bits.ipv6)
     /* EPSV is disabled but we are connected to a IPv6 host, so we ignore the
-       request! */
+       request and enable EPSV again! */
     conn->bits.ftp_use_epsv = TRUE;
-  }
 #endif
 
   for (modeoff = (conn->bits.ftp_use_epsv?0:1);
@@ -1653,7 +1649,7 @@ CURLcode ftp_use_pasv(struct connectdata *conn,
           newport = num;
 
           /* We must use the same IP we are already connected to */
-          Curl_printable_address(conn->ip_addr, newhost, NEWHOST_BUFSIZE);
+          snprintf(newhost, NEWHOST_BUFSIZE, "%s", conn->ip_addr_str);
         }
       }
       else
index c8c4360bed4de401033f5fc93f109acfd908f919..de6d4c2c91eba0813631d9eef1bde54755d9a402 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -1959,6 +1959,8 @@ static CURLcode ConnectPlease(struct connectdata *conn,
     conn->dns_entry = hostaddr;
     conn->ip_addr = addr;
 
+    Curl_store_ip_addr(conn);
+
     if (conn->data->set.proxytype == CURLPROXY_SOCKS5) {
       return handleSock5Proxy(conn->proxyuser,
                               conn->proxypasswd,
@@ -1982,24 +1984,7 @@ static CURLcode ConnectPlease(struct connectdata *conn,
  */
 static void verboseconnect(struct connectdata *conn)
 {
-  struct SessionHandle *data = conn->data;
-  char addrbuf[256];
-
-  /* Get a printable version of the network address. */
-  if(!conn->bits.reuse) {
-    Curl_printable_address(conn->ip_addr, addrbuf, sizeof(addrbuf));
-
-    /* save the string */
-    if(conn->ip_addr_str)
-      free(conn->ip_addr_str);
-    conn->ip_addr_str = strdup(addrbuf);
-    if(!conn->ip_addr_str)
-      return; /* FAIL */
-  }
-  /* else,
-     Re-used, ip_addr is not safe to access. */
-
-  infof(data, "Connected to %s (%s) port %d\n",
+  infof(conn->data, "Connected to %s (%s) port %d\n",
         conn->bits.httpproxy ? conn->proxy.dispname : conn->host.dispname,
         conn->ip_addr_str, conn->port);
 }
index c51ccf3039d0dc683ad0066bdb5d89d0f77c74d7..2068c9a7015cc04d8b333ee74b15c4d87464fbf2 100644 (file)
@@ -293,8 +293,9 @@ struct ConnectBits {
   bool httpproxy;    /* if set, this transfer is done through a http proxy */
   bool user_passwd;    /* do we use user+password for this connection? */
   bool proxy_user_passwd; /* user+password for the proxy? */
-  bool ipv6_ip; /* we communicate with a remove site specified with pure IPv6
+  bool ipv6_ip; /* we communicate with a remote site specified with pure IPv6
                    IP address */
+  bool ipv6;    /* we communicate with a site using an IPv6 address */
   bool use_range;
   bool rangestringalloc; /* the range string is malloc()'ed */
 
@@ -462,8 +463,8 @@ struct connectdata {
 
   /* 'ip_addr_str' is the ip_addr data as a human readable malloc()ed string.
      It remains available as long as the connection does, which is longer than
-     the ip_addr itself. Currently, this is only set (and used) in
-     url.c:verboseconnect(). */
+     the ip_addr itself. Set with Curl_store_ip_addr() when ip_addr has been
+     set. */
   char *ip_addr_str;
 
   char protostr[16];  /* store the protocol string in this buffer */