cURL / Mailing Lists / curl-library / Single Mail

curl-library

[patch submission] libcurl 7.12.0 problems with hostname, proxy and keepalive

From: Bertrand Demiddelaer <bdemiddelaer_at_denyall.com>
Date: Fri, 23 Jul 2004 10:56:01 +0200

Hi,

I had a problem with cookies in a keepalive connection with a proxy. I
sometimes read the message "skipped cookie with bad tailmatch domain",
for a valid cookie. From debug messages, I saw that curl seemed to send
a wrong "Host:" header in the request to the proxy. In fact, the "Host:"
header sent was the one used for the previous request in this handle.

I think it is now solved, but I'm not 100% sure the patch is correct in
every situation. All tests passed (except for the skipped ones...). I
had to modify runtests.pl to be able to use valgrind 2.1.1 which is
installed on my system.

Here's a global patch, including fixes for a few inconsistencies in the
debug messages, a fix to use the good hostname when doing keepalive on a
proxy, and the patch to have runtests.pl testing valgrind version to put
the good options...

Any ideas, suggestions, comments ?

--- lib/cookie.c.00 Mon May 24 09:54:26 2004
+++ lib/cookie.c Tue Jul 6 16:32:45 2004
@@ -254,7 +254,7 @@
               /* Received and skipped a cookie with a domain using too few
                  dots. */
               badcookie=TRUE; /* mark this as a bad cookie */
- infof(data, "skipped cookie with illegal dotcount domain: %s",
+ infof(data, "skipped cookie with illegal dotcount domain: %s\n",
                     whatptr);
             }
             else {
@@ -282,7 +282,7 @@
                    is not a domain to which the current host belongs. Mark as
                    bad. */
                 badcookie=TRUE;
- infof(data, "skipped cookie with bad tailmatch domain: %s",
+ infof(data, "skipped cookie with bad tailmatch domain: %s\n",
                       whatptr);
               }
             }
--- lib/url.c.00 Tue Jul 6 18:03:04 2004
+++ lib/url.c Tue Jul 6 18:27:55 2004
@@ -3019,10 +3019,17 @@
     conn->bits.user_passwd = old_conn->bits.user_passwd;
     conn->bits.proxy_user_passwd = old_conn->bits.proxy_user_passwd;
 
+ /* host can change, when doing keepalive with a proxy ! */
+ if (conn->bits.httpproxy) {
+ free(conn->host.rawalloc);
+ conn->host=old_conn->host;
+ }
+
     /* get the newly set value, not the old one */
     conn->bits.no_body = old_conn->bits.no_body;
 
- free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
+ if (!conn->bits.httpproxy)
+ free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
 
     free(conn->pathbuffer); /* free the newly allocated path pointer */
     conn->pathbuffer = old_conn->pathbuffer; /* use the old one */
@@ -3074,7 +3081,8 @@
     *in_connect = conn; /* return this instead! */
 
     infof(data, "Re-using existing connection! (#%d) with host %s\n",
- conn->connectindex, conn->host.dispname);
+ conn->connectindex,
+ conn->bits.httpproxy?conn->proxy.dispname:conn->host.dispname);
   }
   else {
     /*
@@ -3159,6 +3167,9 @@
     hostaddr = NULL;
     conn->connect_addr = NULL; /* we don't connect now so we don't have any
                                   fresh connect_addr struct to point to */
+
+ if (conn->bits.httpproxy)
+ fix_hostname(conn, &conn->host);
   }
   else {
     /* this is a fresh connect */
@@ -3451,7 +3462,8 @@
   }
   else
     infof(data, "Connection #%d to host %s left intact\n",
- conn->connectindex, conn->host.dispname);
+ conn->connectindex,
+ conn->bits.httpproxy?conn->proxy.dispname:conn->host.dispname);
 
   return result;
 }
--- tests/runtests.pl.00 Mon May 24 00:06:00 2004
+++ tests/runtests.pl Thu Jul 8 17:00:27 2004
@@ -1032,7 +1032,14 @@
     }
 
     if($valgrind) {
- $CMDLINE = "valgrind --leak-check=yes --logfile=log/valgrind$testnum -q $CMDLINE";
+ # since valgrind 2.1.x, '--tool' option is mandatory
+ # use it, if it is supported by the version installed on the system
+ my $valgrind_tool="";
+ system("valgrind --help 2>&1 | grep -- --tool > /dev/null 2>&1");
+ if (($? >> 8)==0) {
+ $valgrind_tool="--tool=memcheck ";
+ }
+ $CMDLINE = "valgrind ".$valgrind_tool."--leak-check=yes --logfile=log/valgrind$testnum -q $CMDLINE";
     }
 
     $CMDLINE .= "$cmdargs >>$STDOUT 2>>$STDERR";
Received on 2004-07-23