diff --git a/debian/changelog b/debian/changelog index 00d8cd9a7dd4492f394f17cdf3e086fbfae7970d..9d652768f4456be1406332d1f8d3a267901814e0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,97 @@ +curl (7.68.0-ok5.6) yangtze; urgency=medium + + * CVE-2023-28321 安全更新: fix host name wildcard checking + + -- Guanzhou Qu Fri, 09 Jan 2026 12:00:00 +0800 + +curl (7.68.0-ok5.5) yangtze; urgency=medium + + * CVE-2023-27533 安全更新: telnet: only accept option arguments in ascii. + + -- tanjin Mon, 27 Oct 2025 16:13:41 +0800 + +curl (7.68.0-ok5.4) yangtze; urgency=medium + + * repair: + CVE-2023-27534 + CVE-2023-23916 + CVE-2023-27536 + * fixed:#187860 + * 需求号:无 + * 其他改动说明: 无 + * 其他改动影响域:无 + + -- zhaikangning Mon, 18 Sep 2023 10:50:41 +0800 + +curl (7.68.0-ok5.3) yangtze; urgency=medium + + * CVE-2023-27538 + + -- icehole Sun, 25 Jun 2023 13:56:09 +0800 + +curl (7.68.0-ok5.2) yangtze; urgency=medium + + * do nothing but rebuild + + -- zhaikangning Wed, 26 Apr 2023 09:22:54 +0800 + +curl (7.68.0-ok5.1) yangtze; urgency=medium + + * Synchronize upstream patches to solve compilation issues + - 同步上游patch,解决编译问题:OpenĹDAP 2.5.4以及之后的版本因为部分函数命名冲突 + + -- zhaikangning Mon, 24 Apr 2023 15:07:15 +0800 + +curl (7.68.0-ok5) yangtze; urgency=medium + + * cn-lwj CVE-2022-43552 安全更新:HTTP Proxy deny use-after-free + + -- liwenjie Wed, 11 Jan 2023 15:49:31 +0800 + +curl (7.68.0-ok4) yangtze; urgency=medium + + * Repair: + CVE-2022-22576 + CVE-2022-27774 + CVE-2022-27775 + CVE-2022-27776 + CVE-2022-27781 + CVE-2022-27782 + CVE-2022-32206 + CVE-2022-32208 + CVE-2022-35252 + CVE-2022-32221 + CVE-2021-22876 + CVE-2021-22890 + CVE-2021-22898 + CVE-2021-22924 + CVE-2021-22925 + CVE-2021-22946 + CVE-2021-22947 + CVE-2020-8169 + CVE-2020-8177 + CVE-2020-8231 + CVE-2020-8284 + CVE-2020-8285 + CVE-2020-8286 + + -- liwenjie Mon, 07 Nov 2022 10:47:35 +0800 + +curl (7.68.0-ok3) yangtze; urgency=medium + + * update version info + + -- luzhiping Mon, 22 Aug 2022 13:52:55 +0800 + +curl (7.68.0-ok2) yangtze; urgency=medium + + * debian/rules: + fix openkylin vendor + + -- Luoyaoming Mon, 06 Jun 2022 11:01:51 +0800 + curl (7.68.0-ok1) yangtze; urgency=medium * Build for openKylin. - -- openKylinBot Mon, 25 Apr 2022 22:03:04 +0800 + -- openKylinBot Mon, 25 Apr 2022 22:03:04 +0800 \ No newline at end of file diff --git a/debian/control b/debian/control index 47593c1de5c85272342049febb2bb09827861d41..cfacbebf0acb83fd2e3e5d39c8565d237aa2f2ae 100644 --- a/debian/control +++ b/debian/control @@ -1,7 +1,7 @@ Source: curl Section: web Priority: optional -Maintainer: Ubuntu Developers +Maintainer: Openkylin Developers XSBC-Original-Maintainer: Alessandro Ghedini Build-Depends: debhelper (>= 12), autoconf, diff --git a/debian/patches/90_gnutls.patch b/debian/extra-patches/90_gnutls.patch similarity index 100% rename from debian/patches/90_gnutls.patch rename to debian/extra-patches/90_gnutls.patch diff --git a/debian/patches/99_nss.patch b/debian/extra-patches/99_nss.patch similarity index 100% rename from debian/patches/99_nss.patch rename to debian/extra-patches/99_nss.patch diff --git a/debian/patches/0009-update-debian-changelog.patch b/debian/patches/0009-update-debian-changelog.patch new file mode 100644 index 0000000000000000000000000000000000000000..09c3229a8f236028aa60894b5429b1f55445c37f --- /dev/null +++ b/debian/patches/0009-update-debian-changelog.patch @@ -0,0 +1,3358 @@ +From: liwenjie +Date: Mon, 7 Nov 2022 10:48:28 +0800 +Subject: update debian/changelog + +--- + docs/cmdline-opts/ftp-skip-pasv-ip.d | 2 + + docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 | 8 +- + lib/conncache.c | 8 +- + lib/connect.c | 20 +-- + lib/content_encoding.c | 9 ++ + lib/cookie.c | 29 ++++ + lib/easy.c | 3 +- + lib/ftp.c | 227 ++++++++++++++------------- + lib/http.c | 34 ++-- + lib/imap.c | 28 ++-- + lib/krb5.c | 5 +- + lib/multi.c | 5 +- + lib/pop3.c | 37 +++-- + lib/setopt.c | 30 ++-- + lib/smtp.c | 4 + + lib/strcase.c | 10 ++ + lib/strcase.h | 2 + + lib/telnet.c | 17 +- + lib/transfer.c | 70 ++++++++- + lib/url.c | 60 +++++-- + lib/urldata.h | 40 +++-- + lib/vssh/ssh.h | 4 +- + lib/vtls/bearssl.c | 9 +- + lib/vtls/gtls.c | 51 +++--- + lib/vtls/mbedtls.c | 8 +- + lib/vtls/mesalink.c | 9 +- + lib/vtls/nss.c | 18 ++- + lib/vtls/openssl.c | 176 ++++++++++++++------- + lib/vtls/schannel.c | 10 +- + lib/vtls/sectransp.c | 9 +- + lib/vtls/vtls.c | 53 ++++++- + lib/vtls/vtls.h | 2 + + lib/vtls/wolfssl.c | 8 +- + src/tool_cb_hdr.c | 22 +-- + src/tool_cfgable.c | 1 + + src/tool_getparam.c | 5 + + tests/data/Makefile.inc | 7 +- + tests/data/test1168 | 78 +++++++++ + tests/data/test1400 | 1 + + tests/data/test1401 | 1 + + tests/data/test1402 | 1 + + tests/data/test1403 | 1 + + tests/data/test1404 | 1 + + tests/data/test1405 | 1 + + tests/data/test1406 | 1 + + tests/data/test1407 | 1 + + tests/data/test1420 | 1 + + tests/data/test973 | 88 +++++++++++ + tests/data/test974 | 87 ++++++++++ + tests/data/test975 | 88 +++++++++++ + tests/data/test976 | 88 +++++++++++ + tests/data/test980 | 52 ++++++ + tests/data/test981 | 59 +++++++ + tests/data/test982 | 57 +++++++ + tests/data/test983 | 52 ++++++ + tests/data/test984 | 56 +++++++ + tests/data/test985 | 54 +++++++ + tests/data/test986 | 53 +++++++ + 58 files changed, 1502 insertions(+), 359 deletions(-) + create mode 100644 tests/data/test1168 + create mode 100644 tests/data/test973 + create mode 100644 tests/data/test974 + create mode 100644 tests/data/test975 + create mode 100644 tests/data/test976 + create mode 100644 tests/data/test980 + create mode 100644 tests/data/test981 + create mode 100644 tests/data/test982 + create mode 100644 tests/data/test983 + create mode 100644 tests/data/test984 + create mode 100644 tests/data/test985 + create mode 100644 tests/data/test986 + +diff --git a/docs/cmdline-opts/ftp-skip-pasv-ip.d b/docs/cmdline-opts/ftp-skip-pasv-ip.d +index da6ab11..4be8b43 100644 +--- a/docs/cmdline-opts/ftp-skip-pasv-ip.d ++++ b/docs/cmdline-opts/ftp-skip-pasv-ip.d +@@ -9,4 +9,6 @@ to curl's PASV command when curl connects the data connection. Instead curl + will re-use the same IP address it already uses for the control + connection. + ++Since curl 7.74.0 this option is enabled by default. ++ + This option has no effect if PORT, EPRT or EPSV is used instead of PASV. +diff --git a/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 b/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 +index 5f234b4..d75204a 100644 +--- a/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 ++++ b/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 +@@ -5,7 +5,7 @@ + .\" * | (__| |_| | _ <| |___ + .\" * \___|\___/|_| \_\_____| + .\" * +-.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. ++.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + .\" * + .\" * This software is licensed as described in the file COPYING, which + .\" * you should have received as part of this distribution. The terms +@@ -36,11 +36,13 @@ address it already uses for the control connection. But it will use the port + number from the 227-response. + + This option thus allows libcurl to work around broken server installations +-that due to NATs, firewalls or incompetence report the wrong IP address back. ++that due to NATs, firewalls or incompetence report the wrong IP address ++back. Setting the option also reduces the risk for various sorts of client ++abuse by malicious servers. + + This option has no effect if PORT, EPRT or EPSV is used instead of PASV. + .SH DEFAULT +-0 ++1 since 7.74.0, was 0 before then. + .SH PROTOCOLS + FTP + .SH EXAMPLE +diff --git a/lib/conncache.c b/lib/conncache.c +index 2804464..42b0ed2 100644 +--- a/lib/conncache.c ++++ b/lib/conncache.c +@@ -158,8 +158,12 @@ static void hashkey(struct connectdata *conn, char *buf, + /* report back which name we used */ + *hostp = hostname; + +- /* put the number first so that the hostname gets cut off if too long */ +- msnprintf(buf, len, "%ld%s", port, hostname); ++ /* put the numbers first so that the hostname gets cut off if too long */ ++#ifdef ENABLE_IPV6 ++ msnprintf(buf, len, "%u/%ld/%s", conn->scope_id, port, hostname); ++#else ++ msnprintf(buf, len, "%ld/%s", port, hostname); ++#endif + } + + void Curl_conncache_unlock(struct Curl_easy *data) +diff --git a/lib/connect.c b/lib/connect.c +index 611d6d2..050acb7 100644 +--- a/lib/connect.c ++++ b/lib/connect.c +@@ -624,6 +624,7 @@ void Curl_persistconninfo(struct connectdata *conn) + conn->data->info.conn_scheme = conn->handler->scheme; + conn->data->info.conn_protocol = conn->handler->protocol; + conn->data->info.conn_primary_port = conn->primary_port; ++ conn->data->info.conn_remote_port = conn->remote_port; + conn->data->info.conn_local_port = conn->local_port; + } + +@@ -1336,15 +1337,15 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ + } + + struct connfind { +- struct connectdata *tofind; +- bool found; ++ long id_tofind; ++ struct connectdata *found; + }; + + static int conn_is_conn(struct connectdata *conn, void *param) + { + struct connfind *f = (struct connfind *)param; +- if(conn == f->tofind) { +- f->found = TRUE; ++ if(conn->connection_id == f->id_tofind) { ++ f->found = conn; + return 1; + } + return 0; +@@ -1366,21 +1367,22 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data, + * - that is associated with a multi handle, and whose connection + * was detached with CURLOPT_CONNECT_ONLY + */ +- if(data->state.lastconnect && (data->multi_easy || data->multi)) { +- struct connectdata *c = data->state.lastconnect; ++ if((data->state.lastconnect_id != -1) && (data->multi_easy || data->multi)) { ++ struct connectdata *c; + struct connfind find; +- find.tofind = data->state.lastconnect; +- find.found = FALSE; ++ find.id_tofind = data->state.lastconnect_id; ++ find.found = NULL; + + Curl_conncache_foreach(data, data->multi_easy? + &data->multi_easy->conn_cache: + &data->multi->conn_cache, &find, conn_is_conn); + + if(!find.found) { +- data->state.lastconnect = NULL; ++ data->state.lastconnect_id = -1; + return CURL_SOCKET_BAD; + } + ++ c = find.found; + if(connp) { + /* only store this if the caller cares for it */ + *connp = c; +diff --git a/lib/content_encoding.c b/lib/content_encoding.c +index 6d47537..e646f31 100644 +--- a/lib/content_encoding.c ++++ b/lib/content_encoding.c +@@ -934,6 +934,9 @@ static const content_encoding *find_encoding(const char *name, size_t len) + return NULL; + } + ++/* allow no more than 5 "chained" compression steps */ ++#define MAX_ENCODE_STACK 5 ++ + /* Set-up the unencoding stack from the Content-Encoding header value. + * See RFC 7231 section 3.1.2.2. */ + CURLcode Curl_build_unencoding_stack(struct connectdata *conn, +@@ -941,6 +944,7 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn, + { + struct Curl_easy *data = conn->data; + struct SingleRequest *k = &data->req; ++ int counter = 0; + + do { + const char *name; +@@ -975,6 +979,11 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn, + if(!encoding) + encoding = &error_encoding; /* Defer error at stack use. */ + ++ if(++counter >= MAX_ENCODE_STACK) { ++ failf(data, "Reject response due to %u content encodings", ++ counter); ++ return CURLE_BAD_CONTENT_ENCODING; ++ } + /* Stack the unencoding stage. */ + writer = new_unencoding_writer(conn, encoding, k->writer_stack); + if(!writer) +diff --git a/lib/cookie.c b/lib/cookie.c +index 0091132..76b6206 100644 +--- a/lib/cookie.c ++++ b/lib/cookie.c +@@ -411,6 +411,30 @@ static bool bad_domain(const char *domain) + return !strchr(domain, '.') && !strcasecompare(domain, "localhost"); + } + ++/* ++ RFC 6265 section 4.1.1 says a server should accept this range: ++ ++ cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E ++ ++ But Firefox and Chrome as of June 2022 accept space, comma and double-quotes ++ fine. The prime reason for filtering out control bytes is that some HTTP ++ servers return 400 for requests that contain such. ++*/ ++static int invalid_octets(const char *p) ++{ ++ /* Reject all bytes \x01 - \x1f (*except* \x09, TAB) + \x7f */ ++ static const char badoctets[] = { ++ "\x01\x02\x03\x04\x05\x06\x07\x08\x0a" ++ "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" ++ "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f" ++ }; ++ size_t vlen, len; ++ /* scan for all the octets that are *not* in cookie-octet */ ++ len = strcspn(p, badoctets); ++ vlen = strlen(p); ++ return (len != vlen); ++} ++ + /**************************************************************************** + * + * Curl_cookie_add() +@@ -557,6 +581,11 @@ Curl_cookie_add(struct Curl_easy *data, + badcookie = TRUE; + break; + } ++ if(invalid_octets(whatptr) || invalid_octets(name)) { ++ infof(data, "invalid octets in name/value, cookie dropped"); ++ badcookie = TRUE; ++ break; ++ } + } + else if(!len) { + /* this was a "=" with no content, and we must allow +diff --git a/lib/easy.c b/lib/easy.c +index 6382cee..3b4c778 100644 +--- a/lib/easy.c ++++ b/lib/easy.c +@@ -832,8 +832,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data) + + /* the connection cache is setup on demand */ + outcurl->state.conn_cache = NULL; +- +- outcurl->state.lastconnect = NULL; ++ outcurl->state.lastconnect_id = -1; + + outcurl->progress.flags = data->progress.flags; + outcurl->progress.callback = data->progress.callback; +diff --git a/lib/ftp.c b/lib/ftp.c +index 469096f..688c11e 100644 +--- a/lib/ftp.c ++++ b/lib/ftp.c +@@ -2497,7 +2497,7 @@ static CURLcode ftp_state_loggedin(struct connectdata *conn) + { + CURLcode result = CURLE_OK; + +- if(conn->ssl[FIRSTSOCKET].use) { ++ if(conn->bits.ftp_use_control_ssl) { + /* PBSZ = PROTECTION BUFFER SIZE. + + The 'draft-murray-auth-ftp-ssl' (draft 12, page 7) says: +@@ -2616,9 +2616,12 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + /* we have now received a full FTP server response */ + switch(ftpc->state) { + case FTP_WAIT220: +- if(ftpcode == 230) +- /* 230 User logged in - already! */ +- return ftp_state_user_resp(conn, ftpcode, ftpc->state); ++ if(ftpcode == 230) { ++ /* 230 User logged in - already! Take as 220 if TLS required. */ ++ if(data->set.use_ssl <= CURLUSESSL_TRY || ++ conn->bits.ftp_use_control_ssl) ++ return ftp_state_user_resp(conn, ftpcode, ftpc->state); ++ } + else if(ftpcode != 220) { + failf(data, "Got a %03d ftp-server response when 220 was expected", + ftpcode); +@@ -2643,11 +2646,8 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + } + #endif + +- if(data->set.use_ssl && +- (!conn->ssl[FIRSTSOCKET].use || +- (conn->bits.proxy_ssl_connected[FIRSTSOCKET] && +- !conn->proxy_ssl[FIRSTSOCKET].use))) { +- /* We don't have a SSL/TLS connection yet, but FTPS is ++ if(data->set.use_ssl && !conn->bits.ftp_use_control_ssl) { ++ /* We don't have a SSL/TLS control connection yet, but FTPS is + requested. Try a FTPS connection now */ + + ftpc->count3 = 0; +@@ -2680,6 +2680,9 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + case FTP_AUTH: + /* we have gotten the response to a previous AUTH command */ + ++ if(pp->cache_size) ++ return CURLE_WEIRD_SERVER_REPLY; /* Forbid pipelining in response. */ ++ + /* RFC2228 (page 5) says: + * + * If the server is willing to accept the named security mechanism, +@@ -2692,6 +2695,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + result = Curl_ssl_connect(conn, FIRSTSOCKET); + if(!result) { + conn->bits.ftp_use_data_ssl = FALSE; /* clear-text data */ ++ conn->bits.ftp_use_control_ssl = TRUE; /* SSL on control */ + result = ftp_state_user(conn); + } + } +@@ -3082,7 +3086,7 @@ static CURLcode ftp_block_statemach(struct connectdata *conn) + * + */ + static CURLcode ftp_connect(struct connectdata *conn, +- bool *done) /* see description above */ ++ bool *done) /* see description above */ + { + CURLcode result; + struct ftp_conn *ftpc = &conn->proto.ftpc; +@@ -3103,6 +3107,7 @@ static CURLcode ftp_connect(struct connectdata *conn, + result = Curl_ssl_connect(conn, FIRSTSOCKET); + if(result) + return result; ++ conn->bits.ftp_use_control_ssl = TRUE; + } + + Curl_pp_init(pp); /* init the generic pingpong data */ +@@ -3773,129 +3778,131 @@ static CURLcode init_wc_data(struct connectdata *conn) + return result; + } + +-/* This is called recursively */ + static CURLcode wc_statemach(struct connectdata *conn) + { + struct WildcardData * const wildcard = &(conn->data->wildcard); + CURLcode result = CURLE_OK; + +- switch(wildcard->state) { +- case CURLWC_INIT: +- result = init_wc_data(conn); +- if(wildcard->state == CURLWC_CLEAN) +- /* only listing! */ +- break; +- wildcard->state = result ? CURLWC_ERROR : CURLWC_MATCHING; +- break; ++ for(;;) { ++ switch(wildcard->state) { ++ case CURLWC_INIT: ++ result = init_wc_data(conn); ++ if(wildcard->state == CURLWC_CLEAN) ++ /* only listing! */ ++ return result; ++ wildcard->state = result ? CURLWC_ERROR : CURLWC_MATCHING; ++ return result; + +- case CURLWC_MATCHING: { +- /* In this state is LIST response successfully parsed, so lets restore +- previous WRITEFUNCTION callback and WRITEDATA pointer */ +- struct ftp_wc *ftpwc = wildcard->protdata; +- conn->data->set.fwrite_func = ftpwc->backup.write_function; +- conn->data->set.out = ftpwc->backup.file_descriptor; +- ftpwc->backup.write_function = ZERO_NULL; +- ftpwc->backup.file_descriptor = NULL; +- wildcard->state = CURLWC_DOWNLOADING; +- +- if(Curl_ftp_parselist_geterror(ftpwc->parser)) { +- /* error found in LIST parsing */ +- wildcard->state = CURLWC_CLEAN; +- return wc_statemach(conn); +- } +- if(wildcard->filelist.size == 0) { +- /* no corresponding file */ +- wildcard->state = CURLWC_CLEAN; +- return CURLE_REMOTE_FILE_NOT_FOUND; ++ case CURLWC_MATCHING: { ++ /* In this state is LIST response successfully parsed, so lets restore ++ previous WRITEFUNCTION callback and WRITEDATA pointer */ ++ struct ftp_wc *ftpwc = wildcard->protdata; ++ conn->data->set.fwrite_func = ftpwc->backup.write_function; ++ conn->data->set.out = ftpwc->backup.file_descriptor; ++ ftpwc->backup.write_function = ZERO_NULL; ++ ftpwc->backup.file_descriptor = NULL; ++ wildcard->state = CURLWC_DOWNLOADING; ++ ++ if(Curl_ftp_parselist_geterror(ftpwc->parser)) { ++ /* error found in LIST parsing */ ++ wildcard->state = CURLWC_CLEAN; ++ continue; ++ } ++ if(wildcard->filelist.size == 0) { ++ /* no corresponding file */ ++ wildcard->state = CURLWC_CLEAN; ++ return CURLE_REMOTE_FILE_NOT_FOUND; ++ } ++ continue; + } +- return wc_statemach(conn); +- } + +- case CURLWC_DOWNLOADING: { +- /* filelist has at least one file, lets get first one */ +- struct ftp_conn *ftpc = &conn->proto.ftpc; +- struct curl_fileinfo *finfo = wildcard->filelist.head->ptr; +- struct FTP *ftp = conn->data->req.protop; ++ case CURLWC_DOWNLOADING: { ++ /* filelist has at least one file, lets get first one */ ++ struct ftp_conn *ftpc = &conn->proto.ftpc; ++ struct curl_fileinfo *finfo = wildcard->filelist.head->ptr; ++ struct FTP *ftp = conn->data->req.protop; + +- char *tmp_path = aprintf("%s%s", wildcard->path, finfo->filename); +- if(!tmp_path) +- return CURLE_OUT_OF_MEMORY; ++ char *tmp_path = aprintf("%s%s", wildcard->path, finfo->filename); ++ if(!tmp_path) ++ return CURLE_OUT_OF_MEMORY; + +- /* switch default ftp->path and tmp_path */ +- free(ftp->pathalloc); +- ftp->pathalloc = ftp->path = tmp_path; +- +- infof(conn->data, "Wildcard - START of \"%s\"\n", finfo->filename); +- if(conn->data->set.chunk_bgn) { +- long userresponse; +- Curl_set_in_callback(conn->data, true); +- userresponse = conn->data->set.chunk_bgn( +- finfo, wildcard->customptr, (int)wildcard->filelist.size); +- Curl_set_in_callback(conn->data, false); +- switch(userresponse) { +- case CURL_CHUNK_BGN_FUNC_SKIP: +- infof(conn->data, "Wildcard - \"%s\" skipped by user\n", +- finfo->filename); +- wildcard->state = CURLWC_SKIP; +- return wc_statemach(conn); +- case CURL_CHUNK_BGN_FUNC_FAIL: +- return CURLE_CHUNK_FAILED; ++ /* switch default ftp->path and tmp_path */ ++ free(ftp->pathalloc); ++ ftp->pathalloc = ftp->path = tmp_path; ++ ++ infof(conn->data, "Wildcard - START of \"%s\"\n", finfo->filename); ++ if(conn->data->set.chunk_bgn) { ++ long userresponse; ++ Curl_set_in_callback(conn->data, true); ++ userresponse = conn->data->set.chunk_bgn( ++ finfo, wildcard->customptr, (int)wildcard->filelist.size); ++ Curl_set_in_callback(conn->data, false); ++ switch(userresponse) { ++ case CURL_CHUNK_BGN_FUNC_SKIP: ++ infof(conn->data, "Wildcard - \"%s\" skipped by user\n", ++ finfo->filename); ++ wildcard->state = CURLWC_SKIP; ++ continue; ++ case CURL_CHUNK_BGN_FUNC_FAIL: ++ return CURLE_CHUNK_FAILED; ++ } + } +- } + +- if(finfo->filetype != CURLFILETYPE_FILE) { +- wildcard->state = CURLWC_SKIP; +- return wc_statemach(conn); +- } ++ if(finfo->filetype != CURLFILETYPE_FILE) { ++ wildcard->state = CURLWC_SKIP; ++ continue; ++ } + +- if(finfo->flags & CURLFINFOFLAG_KNOWN_SIZE) +- ftpc->known_filesize = finfo->size; ++ if(finfo->flags & CURLFINFOFLAG_KNOWN_SIZE) ++ ftpc->known_filesize = finfo->size; + +- result = ftp_parse_url_path(conn); +- if(result) +- return result; ++ result = ftp_parse_url_path(conn); ++ if(result) ++ return result; + +- /* we don't need the Curl_fileinfo of first file anymore */ +- Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); ++ /* we don't need the Curl_fileinfo of first file anymore */ ++ Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); + +- if(wildcard->filelist.size == 0) { /* remains only one file to down. */ +- wildcard->state = CURLWC_CLEAN; +- /* after that will be ftp_do called once again and no transfer +- will be done because of CURLWC_CLEAN state */ +- return CURLE_OK; ++ if(wildcard->filelist.size == 0) { /* remains only one file to down. */ ++ wildcard->state = CURLWC_CLEAN; ++ /* after that will be ftp_do called once again and no transfer ++ will be done because of CURLWC_CLEAN state */ ++ return CURLE_OK; ++ } ++ return result; + } +- } break; + +- case CURLWC_SKIP: { +- if(conn->data->set.chunk_end) { +- Curl_set_in_callback(conn->data, true); +- conn->data->set.chunk_end(conn->data->wildcard.customptr); +- Curl_set_in_callback(conn->data, false); ++ case CURLWC_SKIP: { ++ if(conn->data->set.chunk_end) { ++ Curl_set_in_callback(conn->data, true); ++ conn->data->set.chunk_end(conn->data->wildcard.customptr); ++ Curl_set_in_callback(conn->data, false); ++ } ++ Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); ++ wildcard->state = (wildcard->filelist.size == 0) ? ++ CURLWC_CLEAN : CURLWC_DOWNLOADING; ++ continue; + } +- Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); +- wildcard->state = (wildcard->filelist.size == 0) ? +- CURLWC_CLEAN : CURLWC_DOWNLOADING; +- return wc_statemach(conn); +- } + +- case CURLWC_CLEAN: { +- struct ftp_wc *ftpwc = wildcard->protdata; +- result = CURLE_OK; +- if(ftpwc) +- result = Curl_ftp_parselist_geterror(ftpwc->parser); ++ case CURLWC_CLEAN: { ++ struct ftp_wc *ftpwc = wildcard->protdata; ++ result = CURLE_OK; ++ if(ftpwc) ++ result = Curl_ftp_parselist_geterror(ftpwc->parser); + +- wildcard->state = result ? CURLWC_ERROR : CURLWC_DONE; +- } break; ++ wildcard->state = result ? CURLWC_ERROR : CURLWC_DONE; ++ return result; ++ } + +- case CURLWC_DONE: +- case CURLWC_ERROR: +- case CURLWC_CLEAR: +- if(wildcard->dtor) +- wildcard->dtor(wildcard->protdata); +- break; ++ case CURLWC_DONE: ++ case CURLWC_ERROR: ++ case CURLWC_CLEAR: ++ if(wildcard->dtor) ++ wildcard->dtor(wildcard->protdata); ++ return result; ++ } + } +- +- return result; ++ /* UNREACHABLE */ + } + + /*********************************************************************** +diff --git a/lib/http.c b/lib/http.c +index 837f53c..4d6626b 100644 +--- a/lib/http.c ++++ b/lib/http.c +@@ -733,6 +733,21 @@ output_auth_headers(struct connectdata *conn, + return CURLE_OK; + } + ++/* ++ * allow_auth_to_host() tells if autentication, cookies or other "sensitive ++ * data" can (still) be sent to this host. ++ */ ++static bool allow_auth_to_host(struct Curl_easy *data) ++{ ++ struct connectdata *conn = data->conn; ++ return (!data->state.this_is_a_follow || ++ data->set.allow_auth_to_other_hosts || ++ (data->state.first_host && ++ strcasecompare(data->state.first_host, conn->host.name) && ++ (data->state.first_remote_port == conn->remote_port) && ++ (data->state.first_remote_protocol == conn->handler->protocol))); ++} ++ + /** + * Curl_http_output_auth() setups the authentication headers for the + * host/proxy and the correct authentication +@@ -801,15 +816,12 @@ Curl_http_output_auth(struct connectdata *conn, + with it */ + authproxy->done = TRUE; + +- /* To prevent the user+password to get sent to other than the original +- host due to a location-follow, we do some weirdo checks here */ +- if(!data->state.this_is_a_follow || +- conn->bits.netrc || +- !data->state.first_host || +- data->set.allow_auth_to_other_hosts || +- strcasecompare(data->state.first_host, conn->host.name)) { ++ /* To prevent the user+password to get sent to other than the original host ++ due to a location-follow */ ++ if(allow_auth_to_host(data) ++ || conn->bits.netrc ++ ) + result = output_auth_headers(conn, authhost, request, path, FALSE); +- } + else + authhost->done = TRUE; + +@@ -1881,10 +1893,7 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn, + checkprefix("Cookie:", compare)) && + /* be careful of sending this potentially sensitive header to + other hosts */ +- (data->state.this_is_a_follow && +- data->state.first_host && +- !data->set.allow_auth_to_other_hosts && +- !strcasecompare(data->state.first_host, conn->host.name))) ++ !allow_auth_to_host(data)) + ; + else { + result = Curl_add_bufferf(&req_buffer, "%s\r\n", compare); +@@ -2067,6 +2076,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) + return CURLE_OUT_OF_MEMORY; + + data->state.first_remote_port = conn->remote_port; ++ data->state.first_remote_protocol = conn->handler->protocol; + } + + if((conn->handler->protocol&(PROTO_FAMILY_HTTP|CURLPROTO_FTP)) && +diff --git a/lib/imap.c b/lib/imap.c +index 66172bd..0ca700f 100644 +--- a/lib/imap.c ++++ b/lib/imap.c +@@ -917,22 +917,18 @@ static CURLcode imap_state_capability_resp(struct connectdata *conn, + line += wordlen; + } + } +- else if(imapcode == IMAP_RESP_OK) { +- if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { +- /* We don't have a SSL/TLS connection yet, but SSL is requested */ +- if(imapc->tls_supported) +- /* Switch to TLS connection now */ +- result = imap_perform_starttls(conn); +- else if(data->set.use_ssl == CURLUSESSL_TRY) +- /* Fallback and carry on with authentication */ +- result = imap_perform_authentication(conn); +- else { +- failf(data, "STARTTLS not supported."); +- result = CURLE_USE_SSL_FAILED; +- } ++ else if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { ++ /* PREAUTH is not compatible with STARTTLS. */ ++ if(imapcode == IMAP_RESP_OK && imapc->tls_supported && !imapc->preauth) { ++ /* Switch to TLS connection now */ ++ result = imap_perform_starttls(conn); + } +- else ++ else if(data->set.use_ssl <= CURLUSESSL_TRY) + result = imap_perform_authentication(conn); ++ else { ++ failf(data, "STARTTLS not available."); ++ result = CURLE_USE_SSL_FAILED; ++ } + } + else + result = imap_perform_authentication(conn); +@@ -950,6 +946,10 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + ++ /* Pipelining in response is forbidden. */ ++ if(data->conn->proto.imapc.pp.cache_size) ++ return CURLE_WEIRD_SERVER_REPLY; ++ + if(imapcode != IMAP_RESP_OK) { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied"); +diff --git a/lib/krb5.c b/lib/krb5.c +index f50287a..5b77e35 100644 +--- a/lib/krb5.c ++++ b/lib/krb5.c +@@ -86,11 +86,8 @@ krb5_decode(void *app_data, void *buf, int len, + enc.value = buf; + enc.length = len; + maj = gss_unwrap(&min, *context, &enc, &dec, NULL, NULL); +- if(maj != GSS_S_COMPLETE) { +- if(len >= 4) +- strcpy(buf, "599 "); ++ if(maj != GSS_S_COMPLETE) + return -1; +- } + + memcpy(buf, dec.value, dec.length); + len = curlx_uztosi(dec.length); +diff --git a/lib/multi.c b/lib/multi.c +index 6d819b4..a1d25b6 100644 +--- a/lib/multi.c ++++ b/lib/multi.c +@@ -451,6 +451,7 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi, + data->state.conn_cache = &data->share->conn_cache; + else + data->state.conn_cache = &multi->conn_cache; ++ data->state.lastconnect_id = -1; + + #ifdef USE_LIBPSL + /* Do the same for PSL. */ +@@ -663,11 +664,11 @@ static CURLcode multi_done(struct Curl_easy *data, + CONN_UNLOCK(data); + if(Curl_conncache_return_conn(data, conn)) { + /* remember the most recently used connection */ +- data->state.lastconnect = conn; ++ data->state.lastconnect_id = conn->connection_id; + infof(data, "%s\n", buffer); + } + else +- data->state.lastconnect = NULL; ++ data->state.lastconnect_id = -1; + } + + Curl_free_request_state(data); +diff --git a/lib/pop3.c b/lib/pop3.c +index 57c1373..8a2d52e 100644 +--- a/lib/pop3.c ++++ b/lib/pop3.c +@@ -721,28 +721,23 @@ static CURLcode pop3_state_capa_resp(struct connectdata *conn, int pop3code, + } + } + } +- else if(pop3code == '+') { +- if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { +- /* We don't have a SSL/TLS connection yet, but SSL is requested */ +- if(pop3c->tls_supported) +- /* Switch to TLS connection now */ +- result = pop3_perform_starttls(conn); +- else if(data->set.use_ssl == CURLUSESSL_TRY) +- /* Fallback and carry on with authentication */ +- result = pop3_perform_authentication(conn); +- else { +- failf(data, "STLS not supported."); +- result = CURLE_USE_SSL_FAILED; +- } +- } +- else +- result = pop3_perform_authentication(conn); +- } + else { + /* Clear text is supported when CAPA isn't recognised */ +- pop3c->authtypes |= POP3_TYPE_CLEARTEXT; ++ if(pop3code != '+') ++ pop3c->authtypes |= POP3_TYPE_CLEARTEXT; + +- result = pop3_perform_authentication(conn); ++ if(!data->set.use_ssl || conn->ssl[FIRSTSOCKET].use) ++ result = pop3_perform_authentication(conn); ++ else if(pop3code == '+' && pop3c->tls_supported) ++ /* Switch to TLS connection now */ ++ result = pop3_perform_starttls(conn); ++ else if(data->set.use_ssl <= CURLUSESSL_TRY) ++ /* Fallback and carry on with authentication */ ++ result = pop3_perform_authentication(conn); ++ else { ++ failf(data, "STLS not supported."); ++ result = CURLE_USE_SSL_FAILED; ++ } + } + + return result; +@@ -758,6 +753,10 @@ static CURLcode pop3_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + ++ /* Pipelining in response is forbidden. */ ++ if(data->conn->proto.pop3c.pp.cache_size) ++ return CURLE_WEIRD_SERVER_REPLY; ++ + if(pop3code != '+') { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied"); +diff --git a/lib/setopt.c b/lib/setopt.c +index 5f88ad3..60bdb27 100644 +--- a/lib/setopt.c ++++ b/lib/setopt.c +@@ -486,6 +486,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + } + else + data->set.httpreq = HTTPREQ_GET; ++ data->set.upload = FALSE; + break; + + case CURLOPT_COPYPOSTFIELDS: +@@ -2130,6 +2131,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + + case CURLOPT_SSL_OPTIONS: + arg = va_arg(param, long); ++ data->set.ssl.primary.ssl_options = (unsigned char)(arg & 0xff); + data->set.ssl.enable_beast = + (bool)((arg&CURLSSLOPT_ALLOW_BEAST) ? TRUE : FALSE); + data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE); +@@ -2139,6 +2141,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + #ifndef CURL_DISABLE_PROXY + case CURLOPT_PROXY_SSL_OPTIONS: + arg = va_arg(param, long); ++ data->set.proxy_ssl.primary.ssl_options = (unsigned char)(arg & 0xff); + data->set.proxy_ssl.enable_beast = + (bool)((arg&CURLSSLOPT_ALLOW_BEAST) ? TRUE : FALSE); + data->set.proxy_ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE); +@@ -2537,44 +2540,47 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + case CURLOPT_TLSAUTH_USERNAME: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_ORIG], + va_arg(param, char *)); +- if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype) +- data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && ++ !data->set.ssl.primary.authtype) ++ data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ + break; + case CURLOPT_PROXY_TLSAUTH_USERNAME: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_PROXY], + va_arg(param, char *)); + if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] && +- !data->set.proxy_ssl.authtype) +- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ !data->set.proxy_ssl.primary.authtype) ++ data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default to ++ SRP */ + break; + case CURLOPT_TLSAUTH_PASSWORD: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_ORIG], + va_arg(param, char *)); +- if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype) +- data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && ++ !data->set.ssl.primary.authtype) ++ data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default */ + break; + case CURLOPT_PROXY_TLSAUTH_PASSWORD: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_PROXY], + va_arg(param, char *)); + if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] && +- !data->set.proxy_ssl.authtype) +- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ !data->set.proxy_ssl.primary.authtype) ++ data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default */ + break; + case CURLOPT_TLSAUTH_TYPE: + argptr = va_arg(param, char *); + if(!argptr || + strncasecompare(argptr, "SRP", strlen("SRP"))) +- data->set.ssl.authtype = CURL_TLSAUTH_SRP; ++ data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; + else +- data->set.ssl.authtype = CURL_TLSAUTH_NONE; ++ data->set.ssl.primary.authtype = CURL_TLSAUTH_NONE; + break; + case CURLOPT_PROXY_TLSAUTH_TYPE: + argptr = va_arg(param, char *); + if(!argptr || + strncasecompare(argptr, "SRP", strlen("SRP"))) +- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; ++ data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; + else +- data->set.proxy_ssl.authtype = CURL_TLSAUTH_NONE; ++ data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_NONE; + break; + #endif + #ifdef USE_ARES +diff --git a/lib/smtp.c b/lib/smtp.c +index 65220b0..718b289 100644 +--- a/lib/smtp.c ++++ b/lib/smtp.c +@@ -680,6 +680,10 @@ static CURLcode smtp_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + ++ /* Pipelining in response is forbidden. */ ++ if(data->conn->proto.smtpc.pp.cache_size) ++ return CURLE_WEIRD_SERVER_REPLY; ++ + if(smtpcode != 220) { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied, code %d", smtpcode); +diff --git a/lib/strcase.c b/lib/strcase.c +index a894712..68e2773 100644 +--- a/lib/strcase.c ++++ b/lib/strcase.c +@@ -249,6 +249,16 @@ void Curl_strntolower(char *dest, const char *src, size_t n) + } while(*src++ && --n); + } + ++/* Compare case-sensitive NUL-terminated strings, taking care of possible ++ * null pointers. Return true if arguments match. ++ */ ++bool Curl_safecmp(char *a, char *b) ++{ ++ if(a && b) ++ return !strcmp(a, b); ++ return !a && !b; ++} ++ + /* --- public functions --- */ + + int curl_strequal(const char *first, const char *second) +diff --git a/lib/strcase.h b/lib/strcase.h +index baa768b..3665d5a 100644 +--- a/lib/strcase.h ++++ b/lib/strcase.h +@@ -49,4 +49,6 @@ char Curl_raw_tolower(char in); + void Curl_strntoupper(char *dest, const char *src, size_t n); + void Curl_strntolower(char *dest, const char *src, size_t n); + ++bool Curl_safecmp(char *a, char *b); ++ + #endif /* HEADER_CURL_STRCASE_H */ +diff --git a/lib/telnet.c b/lib/telnet.c +index 4bf4c65..3347ad6 100644 +--- a/lib/telnet.c ++++ b/lib/telnet.c +@@ -967,12 +967,17 @@ static void suboption(struct connectdata *conn) + size_t tmplen = (strlen(v->data) + 1); + /* Add the variable only if it fits */ + if(len + tmplen < (int)sizeof(temp)-6) { +- if(sscanf(v->data, "%127[^,],%127s", varname, varval)) { +- msnprintf((char *)&temp[len], sizeof(temp) - len, +- "%c%s%c%s", CURL_NEW_ENV_VAR, varname, +- CURL_NEW_ENV_VALUE, varval); +- len += tmplen; +- } ++ int rv; ++ char sep[2] = ""; ++ varval[0] = 0; ++ rv = sscanf(v->data, "%127[^,]%1[,]%127s", varname, sep, varval); ++ if(rv == 1) ++ len += msnprintf((char *)&temp[len], sizeof(temp) - len, ++ "%c%s", CURL_NEW_ENV_VAR, varname); ++ else if(rv >= 2) ++ len += msnprintf((char *)&temp[len], sizeof(temp) - len, ++ "%c%s%c%s", CURL_NEW_ENV_VAR, varname, ++ CURL_NEW_ENV_VALUE, varval); + } + } + msnprintf((char *)&temp[len], sizeof(temp) - len, +diff --git a/lib/transfer.c b/lib/transfer.c +index ead8b36..f279c5b 100644 +--- a/lib/transfer.c ++++ b/lib/transfer.c +@@ -1572,6 +1572,9 @@ CURLcode Curl_follow(struct Curl_easy *data, + data->set.followlocation++; /* count location-followers */ + + if(data->set.http_auto_referer) { ++ CURLU *u; ++ char *referer; ++ + /* We are asked to automatically set the previous URL as the referer + when we get the next URL. We pick the ->url field, which may or may + not be 100% correct */ +@@ -1581,9 +1584,27 @@ CURLcode Curl_follow(struct Curl_easy *data, + data->change.referer_alloc = FALSE; + } + +- data->change.referer = strdup(data->change.url); +- if(!data->change.referer) ++ /* Make a copy of the URL without crenditals and fragment */ ++ u = curl_url(); ++ if(!u) ++ return CURLE_OUT_OF_MEMORY; ++ ++ uc = curl_url_set(u, CURLUPART_URL, data->change.url, 0); ++ if(!uc) ++ uc = curl_url_set(u, CURLUPART_FRAGMENT, NULL, 0); ++ if(!uc) ++ uc = curl_url_set(u, CURLUPART_USER, NULL, 0); ++ if(!uc) ++ uc = curl_url_set(u, CURLUPART_PASSWORD, NULL, 0); ++ if(!uc) ++ uc = curl_url_get(u, CURLUPART_URL, &referer, 0); ++ ++ curl_url_cleanup(u); ++ ++ if(uc || referer == NULL) + return CURLE_OUT_OF_MEMORY; ++ ++ data->change.referer = referer; + data->change.referer_alloc = TRUE; /* yes, free this later */ + } + } +@@ -1608,10 +1629,53 @@ CURLcode Curl_follow(struct Curl_easy *data, + return CURLE_OUT_OF_MEMORY; + } + else { +- + uc = curl_url_get(data->state.uh, CURLUPART_URL, &newurl, 0); + if(uc) + return Curl_uc_to_curlcode(uc); ++ ++ /* Clear auth if this redirects to a different port number or protocol, ++ unless permitted */ ++ if(!data->set.allow_auth_to_other_hosts && (type != FOLLOW_FAKE)) { ++ char *portnum; ++ int port; ++ bool clear = FALSE; ++ ++ uc = curl_url_get(data->state.uh, CURLUPART_PORT, &portnum, ++ CURLU_DEFAULT_PORT); ++ if(uc) { ++ free(newurl); ++ return Curl_uc_to_curlcode(uc); ++ } ++ port = atoi(portnum); ++ free(portnum); ++ ++ if(port != data->info.conn_remote_port) { ++ infof(data, "Clear auth, redirects to port from %u to %u", ++ data->info.conn_remote_port, port); ++ clear = TRUE; ++ } ++ else { ++ char *scheme; ++ const struct Curl_handler *p; ++ uc = curl_url_get(data->state.uh, CURLUPART_SCHEME, &scheme, 0); ++ if(uc) { ++ free(newurl); ++ return Curl_uc_to_curlcode(uc); ++ } ++ ++ p = Curl_builtin_scheme(scheme); ++ if(p && (p->protocol != data->info.conn_protocol)) { ++ infof(data, "Clear auth, redirects scheme from %s to %s", ++ data->info.conn_scheme, scheme); ++ clear = TRUE; ++ } ++ free(scheme); ++ } ++ if(clear) { ++ Curl_safefree(data->set.str[STRING_USERNAME]); ++ Curl_safefree(data->set.str[STRING_PASSWORD]); ++ } ++ } + } + + if(type == FOLLOW_FAKE) { +diff --git a/lib/url.c b/lib/url.c +index 56fb736..01f7eda 100644 +--- a/lib/url.c ++++ b/lib/url.c +@@ -456,6 +456,7 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) + set->ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */ + set->ftp_use_pret = FALSE; /* mainly useful for drftpd servers */ + set->ftp_filemethod = FTPFILE_MULTICWD; ++ set->ftp_skip_ip = TRUE; /* skip PASV IP by default */ + #endif + set->dns_cache_timeout = 60; /* Timeout every 60 seconds by default */ + +@@ -482,7 +483,7 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) + set->ssl.primary.verifypeer = TRUE; + set->ssl.primary.verifyhost = TRUE; + #ifdef USE_TLS_SRP +- set->ssl.authtype = CURL_TLSAUTH_NONE; ++ set->ssl.primary.authtype = CURL_TLSAUTH_NONE; + #endif + set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth + type */ +@@ -618,7 +619,7 @@ CURLcode Curl_open(struct Curl_easy **curl) + Curl_initinfo(data); + + /* most recent connection is not yet defined */ +- data->state.lastconnect = NULL; ++ data->state.lastconnect_id = -1; + + data->progress.flags |= PGRS_HIDE; + data->state.current_speed = -1; /* init to negative == impossible */ +@@ -996,6 +997,12 @@ static void prune_dead_connections(struct Curl_easy *data) + } + } + ++static bool ssh_config_matches(struct connectdata *one, ++ struct connectdata *two) ++{ ++ return (Curl_safecmp(one->proto.sshc.rsa, two->proto.sshc.rsa) && ++ Curl_safecmp(one->proto.sshc.rsa_pub, two->proto.sshc.rsa_pub)); ++} + /* + * Given one filled in connection struct (named needle), this function should + * detect if there already is one that has all the significant details +@@ -1218,12 +1225,19 @@ ConnectionExists(struct Curl_easy *data, + /* This protocol requires credentials per connection, + so verify that we're using the same name and password as well */ + if(strcmp(needle->user, check->user) || +- strcmp(needle->passwd, check->passwd)) { ++ strcmp(needle->passwd, check->passwd) || ++ !Curl_safecmp(needle->sasl_authzid, check->sasl_authzid) || ++ !Curl_safecmp(needle->oauth_bearer, check->oauth_bearer)) { + /* one of them was different */ + continue; + } + } + ++ if(get_protocol_family(needle->handler->protocol) == PROTO_FAMILY_SSH) { ++ if(!ssh_config_matches(needle, check)) ++ continue; ++ } ++ + if(!needle->bits.httpproxy || (needle->handler->flags&PROTOPT_SSL) || + needle->bits.tunnel_proxy) { + /* The requested connection does not use a HTTP proxy or it uses SSL or +@@ -1605,10 +1619,16 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) + conn->ssl_config.verifystatus = data->set.ssl.primary.verifystatus; + conn->ssl_config.verifypeer = data->set.ssl.primary.verifypeer; + conn->ssl_config.verifyhost = data->set.ssl.primary.verifyhost; ++ conn->ssl_config.ssl_options = data->set.ssl.primary.ssl_options; ++#ifdef USE_TLS_SRP ++#endif + conn->proxy_ssl_config.verifystatus = + data->set.proxy_ssl.primary.verifystatus; + conn->proxy_ssl_config.verifypeer = data->set.proxy_ssl.primary.verifypeer; + conn->proxy_ssl_config.verifyhost = data->set.proxy_ssl.primary.verifyhost; ++ conn->proxy_ssl_config.ssl_options = data->set.proxy_ssl.primary.ssl_options; ++#ifdef USE_TLS_SRP ++#endif + conn->ip_version = data->set.ipver; + conn->bits.connect_only = data->set.connect_only; + conn->transport = TRNSPRT_TCP; /* most of them are TCP streams */ +@@ -2733,12 +2753,14 @@ static CURLcode override_login(struct Curl_easy *data, + + /* for updated strings, we update them in the URL */ + if(user_changed) { +- uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp, 0); ++ uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp, ++ CURLU_URLENCODE); + if(uc) + return Curl_uc_to_curlcode(uc); + } + if(passwd_changed) { +- uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp, 0); ++ uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp, ++ CURLU_URLENCODE); + if(uc) + return Curl_uc_to_curlcode(uc); + } +@@ -3352,6 +3374,14 @@ static CURLcode create_conn(struct Curl_easy *data, + } + } + ++ if(data->set.str[STRING_BEARER]) { ++ conn->oauth_bearer = strdup(data->set.str[STRING_BEARER]); ++ if(!conn->oauth_bearer) { ++ result = CURLE_OUT_OF_MEMORY; ++ goto out; ++ } ++ } ++ + #ifdef USE_UNIX_SOCKETS + if(data->set.str[STRING_UNIX_SOCKET_PATH]) { + conn->unix_domain_socket = strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); +@@ -3520,6 +3550,9 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.proxy_ssl.primary.CApath = data->set.str[STRING_SSL_CAPATH_PROXY]; + data->set.ssl.primary.CAfile = data->set.str[STRING_SSL_CAFILE_ORIG]; + data->set.proxy_ssl.primary.CAfile = data->set.str[STRING_SSL_CAFILE_PROXY]; ++ data->set.ssl.primary.issuercert = data->set.str[STRING_SSL_ISSUERCERT_ORIG]; ++ data->set.proxy_ssl.primary.issuercert = ++ data->set.str[STRING_SSL_ISSUERCERT_PROXY]; + data->set.ssl.primary.random_file = data->set.str[STRING_SSL_RANDOM_FILE]; + data->set.proxy_ssl.primary.random_file = + data->set.str[STRING_SSL_RANDOM_FILE]; +@@ -3538,10 +3571,9 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.proxy_ssl.primary.pinned_key = + data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY]; + +- data->set.ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_ORIG]; +- data->set.proxy_ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_PROXY]; +- data->set.ssl.issuercert = data->set.str[STRING_SSL_ISSUERCERT_ORIG]; +- data->set.proxy_ssl.issuercert = data->set.str[STRING_SSL_ISSUERCERT_PROXY]; ++ data->set.ssl.primary.CRLfile = data->set.str[STRING_SSL_CRLFILE_ORIG]; ++ data->set.proxy_ssl.primary.CRLfile = ++ data->set.str[STRING_SSL_CRLFILE_PROXY]; + data->set.ssl.cert = data->set.str[STRING_CERT_ORIG]; + data->set.proxy_ssl.cert = data->set.str[STRING_CERT_PROXY]; + data->set.ssl.cert_type = data->set.str[STRING_CERT_TYPE_ORIG]; +@@ -3555,10 +3587,12 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.ssl.primary.clientcert = data->set.str[STRING_CERT_ORIG]; + data->set.proxy_ssl.primary.clientcert = data->set.str[STRING_CERT_PROXY]; + #ifdef USE_TLS_SRP +- data->set.ssl.username = data->set.str[STRING_TLSAUTH_USERNAME_ORIG]; +- data->set.proxy_ssl.username = data->set.str[STRING_TLSAUTH_USERNAME_PROXY]; +- data->set.ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD_ORIG]; +- data->set.proxy_ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD_PROXY]; ++ data->set.ssl.primary.username = data->set.str[STRING_TLSAUTH_USERNAME_ORIG]; ++ data->set.proxy_ssl.primary.username = ++ data->set.str[STRING_TLSAUTH_USERNAME_PROXY]; ++ data->set.ssl.primary.password = data->set.str[STRING_TLSAUTH_PASSWORD_ORIG]; ++ data->set.proxy_ssl.primary.password = ++ data->set.str[STRING_TLSAUTH_PASSWORD_PROXY]; + #endif + + if(!Curl_clone_primary_ssl_config(&data->set.ssl.primary, +diff --git a/lib/urldata.h b/lib/urldata.h +index 3effb16..8f3c31d 100644 +--- a/lib/urldata.h ++++ b/lib/urldata.h +@@ -224,12 +224,20 @@ struct ssl_primary_config { + long version_max; /* max supported version the client wants to use*/ + char *CApath; /* certificate dir (doesn't work on windows) */ + char *CAfile; /* certificate to verify peer against */ ++ char *issuercert; /* optional issuer certificate filename */ + char *clientcert; + char *random_file; /* path to file containing "random" data */ + char *egdsocket; /* path to file containing the EGD daemon socket */ + char *cipher_list; /* list of ciphers to use */ + char *cipher_list13; /* list of TLS 1.3 cipher suites to use */ + char *pinned_key; ++ char *CRLfile; /* CRL to check certificate revocation */ ++#ifdef USE_TLS_SRP ++ char *username; /* TLS username (for, e.g., SRP) */ ++ char *password; /* TLS password (for, e.g., SRP) */ ++ enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */ ++#endif ++ unsigned char ssl_options; /* the CURLOPT_SSL_OPTIONS bitmask */ + BIT(verifypeer); /* set TRUE if this is desired */ + BIT(verifyhost); /* set TRUE if CN/SAN must match hostname */ + BIT(verifystatus); /* set TRUE if certificate status must be checked */ +@@ -239,8 +247,6 @@ struct ssl_primary_config { + struct ssl_config_data { + struct ssl_primary_config primary; + long certverifyresult; /* result from the certificate verification */ +- char *CRLfile; /* CRL to check certificate revocation */ +- char *issuercert;/* optional issuer certificate filename */ + curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */ + void *fsslctxp; /* parameter for call back */ + char *cert; /* client certificate file name */ +@@ -248,11 +254,6 @@ struct ssl_config_data { + char *key; /* private key file name */ + char *key_type; /* format for private key (default: PEM) */ + char *key_passwd; /* plain text private key password */ +-#ifdef USE_TLS_SRP +- char *username; /* TLS username (for, e.g., SRP) */ +- char *password; /* TLS password (for, e.g., SRP) */ +- enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */ +-#endif + BIT(certinfo); /* gather lots of certificate info */ + BIT(falsestart); + BIT(enable_beast); /* allow this flaw for interoperability's sake*/ +@@ -453,6 +454,7 @@ struct ConnectBits { + EPRT doesn't work we disable it for the forthcoming + requests */ + BIT(ftp_use_data_ssl); /* Enabled SSL for the data connection */ ++ BIT(ftp_use_control_ssl); /* Enabled SSL for the control connection */ + #endif + BIT(netrc); /* name+password provided by netrc */ + BIT(userpwd_in_url); /* name+password found in url */ +@@ -1114,7 +1116,11 @@ struct PureInfo { + reused, in the connection cache. */ + + char conn_primary_ip[MAX_IPADR_LEN]; +- long conn_primary_port; ++ int conn_primary_port; /* this is the destination port to the connection, ++ which might have been a proxy */ ++ int conn_remote_port; /* this is the "remote port", which is the port ++ number of the used URL, independent of proxy or ++ not */ + char conn_local_ip[MAX_IPADR_LEN]; + long conn_local_port; + const char *conn_scheme; +@@ -1301,7 +1307,7 @@ struct UrlState { + /* buffers to store authentication data in, as parsed from input options */ + struct curltime keeps_speed; /* for the progress meter really */ + +- struct connectdata *lastconnect; /* The last connection, NULL if undefined */ ++ long lastconnect_id; /* The last connection, -1 if undefined */ + + char *headerbuff; /* allocated buffer to store headers in */ + size_t headersize; /* size of the allocation */ +@@ -1310,13 +1316,15 @@ struct UrlState { + char *ulbuf; /* allocated upload buffer or NULL */ + curl_off_t current_speed; /* the ProgressShow() function sets this, + bytes / second */ +- char *first_host; /* host name of the first (not followed) request. +- if set, this should be the host name that we will +- sent authorization to, no else. Used to make Location: +- following not keep sending user+password... This is +- strdup() data. +- */ +- int first_remote_port; /* remote port of the first (not followed) request */ ++ ++ /* host name, port number and protocol of the first (not followed) request. ++ if set, this should be the host name that we will sent authorization to, ++ no else. Used to make Location: following not keep sending user+password. ++ This is strdup()ed data. */ ++ char *first_host; ++ int first_remote_port; ++ unsigned int first_remote_protocol; ++ + struct curl_ssl_session *session; /* array of 'max_ssl_sessions' size */ + long sessionage; /* number of the most recent session */ + unsigned int tempcount; /* number of entries in use in tempwrite, 0 - 3 */ +diff --git a/lib/vssh/ssh.h b/lib/vssh/ssh.h +index 3213c5a..e9e5a34 100644 +--- a/lib/vssh/ssh.h ++++ b/lib/vssh/ssh.h +@@ -117,8 +117,8 @@ struct ssh_conn { + + /* common */ + const char *passphrase; /* pass-phrase to use */ +- char *rsa_pub; /* path name */ +- char *rsa; /* path name */ ++ char *rsa_pub; /* strdup'ed public key file */ ++ char *rsa; /* strdup'ed private key file */ + bool authed; /* the connection has been authenticated fine */ + sshstate state; /* always use ssh.c:state() to change state! */ + sshstate nextstate; /* the state to goto after stopping */ +diff --git a/lib/vtls/bearssl.c b/lib/vtls/bearssl.c +index 67f9458..32cb0a4 100644 +--- a/lib/vtls/bearssl.c ++++ b/lib/vtls/bearssl.c +@@ -372,7 +372,8 @@ static CURLcode bearssl_connect_step1(struct connectdata *conn, int sockindex) + void *session; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &session, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &session, NULL, sockindex)) { + br_ssl_engine_set_session_parameters(&BACKEND->ctx.eng, session); + infof(data, "BearSSL: re-using session ID\n"); + } +@@ -560,10 +561,12 @@ static CURLcode bearssl_connect_step3(struct connectdata *conn, int sockindex) + return CURLE_OUT_OF_MEMORY; + br_ssl_engine_get_session_parameters(&BACKEND->ctx.eng, session); + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, &oldsession, NULL, sockindex)); ++ incache = !(Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &oldsession, NULL, sockindex)); + if(incache) + Curl_ssl_delsessionid(conn, oldsession); +- ret = Curl_ssl_addsessionid(conn, session, 0, sockindex); ++ ret = Curl_ssl_addsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ session, 0, sockindex); + Curl_ssl_sessionid_unlock(conn); + if(ret) { + free(session); +diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c +index 571e83b..92dbcd5 100644 +--- a/lib/vtls/gtls.c ++++ b/lib/vtls/gtls.c +@@ -581,8 +581,9 @@ gtls_connect_step1(struct connectdata *conn, + } + + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { +- infof(data, "Using TLS-SRP username: %s\n", SSL_SET_OPTION(username)); ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { ++ infof(data, "Using TLS-SRP username: %s\n", ++ SSL_SET_OPTION(primary.username)); + + rc = gnutls_srp_allocate_client_credentials( + &BACKEND->srp_client_cred); +@@ -593,8 +594,8 @@ gtls_connect_step1(struct connectdata *conn, + } + + rc = gnutls_srp_set_client_credentials(BACKEND->srp_client_cred, +- SSL_SET_OPTION(username), +- SSL_SET_OPTION(password)); ++ SSL_SET_OPTION(primary.username), ++ SSL_SET_OPTION(primary.password)); + if(rc != GNUTLS_E_SUCCESS) { + failf(data, "gnutls_srp_set_client_cred() failed: %s", + gnutls_strerror(rc)); +@@ -648,19 +649,19 @@ gtls_connect_step1(struct connectdata *conn, + } + #endif + +- if(SSL_SET_OPTION(CRLfile)) { ++ if(SSL_SET_OPTION(primary.CRLfile)) { + /* set the CRL list file */ + rc = gnutls_certificate_set_x509_crl_file(BACKEND->cred, +- SSL_SET_OPTION(CRLfile), ++ SSL_SET_OPTION(primary.CRLfile), + GNUTLS_X509_FMT_PEM); + if(rc < 0) { + failf(data, "error reading crl file %s (%s)", +- SSL_SET_OPTION(CRLfile), gnutls_strerror(rc)); ++ SSL_SET_OPTION(primary.CRLfile), gnutls_strerror(rc)); + return CURLE_SSL_CRL_BADFILE; + } + else + infof(data, "found %d CRL in %s\n", +- rc, SSL_SET_OPTION(CRLfile)); ++ rc, SSL_SET_OPTION(primary.CRLfile)); + } + + /* Initialize TLS session as a client */ +@@ -787,7 +788,7 @@ gtls_connect_step1(struct connectdata *conn, + #ifdef USE_TLS_SRP + /* Only add SRP to the cipher list if SRP is requested. Otherwise + * GnuTLS will disable TLS 1.3 support. */ +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { + size_t len = strlen(prioritylist); + + char *prioritysrp = malloc(len + sizeof(GNUTLS_SRP) + 1); +@@ -884,7 +885,7 @@ gtls_connect_step1(struct connectdata *conn, + + #ifdef USE_TLS_SRP + /* put the credentials to the current session */ +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { + rc = gnutls_credentials_set(session, GNUTLS_CRD_SRP, + BACKEND->srp_client_cred); + if(rc != GNUTLS_E_SUCCESS) { +@@ -942,7 +943,8 @@ gtls_connect_step1(struct connectdata *conn, + size_t ssl_idsize; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, &ssl_idsize, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, &ssl_idsize, sockindex)) { + /* we got a session id, use it! */ + gnutls_session_set_data(session, ssl_sessionid, ssl_idsize); + +@@ -1063,10 +1065,10 @@ gtls_connect_step3(struct connectdata *conn, + if(!chainp) { + if(SSL_CONN_CONFIG(verifypeer) || + SSL_CONN_CONFIG(verifyhost) || +- SSL_SET_OPTION(issuercert)) { ++ SSL_CONN_CONFIG(issuercert)) { + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP +- && SSL_SET_OPTION(username) != NULL ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP ++ && SSL_SET_OPTION(primary.username) != NULL + && !SSL_CONN_CONFIG(verifypeer) + && gnutls_cipher_get(session)) { + /* no peer cert, but auth is ok if we have SRP user and cipher and no +@@ -1120,7 +1122,8 @@ gtls_connect_step3(struct connectdata *conn, + failf(data, "server certificate verification failed. CAfile: %s " + "CRLfile: %s", SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile): + "none", +- SSL_SET_OPTION(CRLfile)?SSL_SET_OPTION(CRLfile):"none"); ++ SSL_SET_OPTION(primary.CRLfile) ? ++ SSL_SET_OPTION(primary.CRLfile) : "none"); + return CURLE_PEER_FAILED_VERIFICATION; + } + else +@@ -1245,21 +1248,21 @@ gtls_connect_step3(struct connectdata *conn, + gnutls_x509_crt_t format */ + gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER); + +- if(SSL_SET_OPTION(issuercert)) { ++ if(SSL_CONN_CONFIG(issuercert)) { + gnutls_x509_crt_init(&x509_issuer); +- issuerp = load_file(SSL_SET_OPTION(issuercert)); ++ issuerp = load_file(SSL_CONN_CONFIG(issuercert)); + gnutls_x509_crt_import(x509_issuer, &issuerp, GNUTLS_X509_FMT_PEM); + rc = gnutls_x509_crt_check_issuer(x509_cert, x509_issuer); + gnutls_x509_crt_deinit(x509_issuer); + unload_file(issuerp); + if(rc <= 0) { + failf(data, "server certificate issuer check failed (IssuerCert: %s)", +- SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none"); ++ SSL_CONN_CONFIG(issuercert)?SSL_CONN_CONFIG(issuercert):"none"); + gnutls_x509_crt_deinit(x509_cert); + return CURLE_SSL_ISSUER_ERROR; + } + infof(data, "\t server certificate issuer check OK (Issuer Cert: %s)\n", +- SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none"); ++ SSL_CONN_CONFIG(issuercert)?SSL_CONN_CONFIG(issuercert):"none"); + } + + size = sizeof(certbuf); +@@ -1490,7 +1493,8 @@ gtls_connect_step3(struct connectdata *conn, + gnutls_session_get_data(session, connect_sessionid, &connect_idsize); + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, NULL, + sockindex)); + if(incache) { + /* there was one before in the cache, so instead of risking that the +@@ -1499,7 +1503,8 @@ gtls_connect_step3(struct connectdata *conn, + } + + /* store this session id */ +- result = Curl_ssl_addsessionid(conn, connect_sessionid, connect_idsize, ++ result = Curl_ssl_addsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ connect_sessionid, connect_idsize, + sockindex); + Curl_ssl_sessionid_unlock(conn); + if(result) { +@@ -1705,8 +1710,8 @@ static int Curl_gtls_shutdown(struct connectdata *conn, int sockindex) + gnutls_certificate_free_credentials(BACKEND->cred); + + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP +- && SSL_SET_OPTION(username) != NULL) ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP ++ && SSL_SET_OPTION(primary.username) != NULL) + gnutls_srp_free_client_credentials(BACKEND->srp_client_cred); + #endif + +diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c +index e34ec9d..783ecd9 100644 +--- a/lib/vtls/mbedtls.c ++++ b/lib/vtls/mbedtls.c +@@ -453,7 +453,8 @@ mbed_connect_step1(struct connectdata *conn, + void *old_session = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &old_session, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &old_session, NULL, sockindex)) { + ret = mbedtls_ssl_set_session(&BACKEND->ssl, old_session); + if(ret) { + Curl_ssl_sessionid_unlock(conn); +@@ -709,6 +710,7 @@ mbed_connect_step3(struct connectdata *conn, + int ret; + mbedtls_ssl_session *our_ssl_sessionid; + void *old_ssl_sessionid = NULL; ++ bool isproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + our_ssl_sessionid = malloc(sizeof(mbedtls_ssl_session)); + if(!our_ssl_sessionid) +@@ -727,10 +729,10 @@ mbed_connect_step3(struct connectdata *conn, + + /* If there's already a matching session in the cache, delete it */ + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, sockindex)) ++ if(!Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, NULL, sockindex)) + Curl_ssl_delsessionid(conn, old_ssl_sessionid); + +- retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid, 0, sockindex); ++ retcode = Curl_ssl_addsessionid(conn, isproxy, our_ssl_sessionid, 0, sockindex); + Curl_ssl_sessionid_unlock(conn); + if(retcode) { + mbedtls_ssl_session_free(our_ssl_sessionid); +diff --git a/lib/vtls/mesalink.c b/lib/vtls/mesalink.c +index cab1e39..79d1e3d 100644 +--- a/lib/vtls/mesalink.c ++++ b/lib/vtls/mesalink.c +@@ -263,7 +263,8 @@ mesalink_connect_step1(struct connectdata *conn, int sockindex) + void *ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + Curl_ssl_sessionid_unlock(conn); +@@ -347,12 +348,14 @@ mesalink_connect_step3(struct connectdata *conn, int sockindex) + bool incache; + SSL_SESSION *our_ssl_sessionid; + void *old_ssl_sessionid = NULL; ++ bool inproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + our_ssl_sessionid = SSL_get_session(BACKEND->handle); + + Curl_ssl_sessionid_lock(conn); + incache = +- !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, sockindex)); ++ !(Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, ++ NULL, sockindex)); + if(incache) { + if(old_ssl_sessionid != our_ssl_sessionid) { + infof(data, "old SSL session ID is stale, removing\n"); +@@ -363,7 +366,7 @@ mesalink_connect_step3(struct connectdata *conn, int sockindex) + + if(!incache) { + result = Curl_ssl_addsessionid( +- conn, our_ssl_sessionid, 0 /* unknown size */, sockindex); ++ conn, isproxy, our_ssl_sessionid, 0 /* unknown size */, sockindex); + if(result) { + Curl_ssl_sessionid_unlock(conn); + failf(data, "failed to store ssl session"); +diff --git a/lib/vtls/nss.c b/lib/vtls/nss.c +index ef51b0d..af8706c 100644 +--- a/lib/vtls/nss.c ++++ b/lib/vtls/nss.c +@@ -950,6 +950,9 @@ static void display_cert_info(struct Curl_easy *data, + PR_Free(common_name); + } + ++/* A number of certs that will never occur in a real server handshake */ ++#define TOO_MANY_CERTS 300 ++ + static CURLcode display_conn_info(struct connectdata *conn, PRFileDesc *sock) + { + CURLcode result = CURLE_OK; +@@ -986,6 +989,11 @@ static CURLcode display_conn_info(struct connectdata *conn, PRFileDesc *sock) + cert2 = CERT_FindCertIssuer(cert, now, certUsageSSLCA); + while(cert2) { + i++; ++ if(i >= TOO_MANY_CERTS) { ++ CERT_DestroyCertificate(cert2); ++ failf(conn->data, "certificate loop"); ++ return CURLE_SSL_CERTPROBLEM; ++ } + if(cert2->isRoot) { + CERT_DestroyCertificate(cert2); + break; +@@ -1947,13 +1955,13 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex) + } + } + +- if(SSL_SET_OPTION(CRLfile)) { +- const CURLcode rv = nss_load_crl(SSL_SET_OPTION(CRLfile)); ++ if(SSL_SET_OPTION(primary.CRLfile)) { ++ const CURLcode rv = nss_load_crl(SSL_SET_OPTION(primary.CRLfile)); + if(rv) { + result = rv; + goto error; + } +- infof(data, " CRLfile: %s\n", SSL_SET_OPTION(CRLfile)); ++ infof(data, " CRLfile: %s\n", SSL_SET_OPTION(primary.CRLfile)); + } + + if(SSL_SET_OPTION(cert)) { +@@ -2151,9 +2159,9 @@ static CURLcode nss_do_connect(struct connectdata *conn, int sockindex) + if(result) + goto error; + +- if(SSL_SET_OPTION(issuercert)) { ++ if(SSL_CONN_CONFIG(issuercert)) { + SECStatus ret = SECFailure; +- char *nickname = dup_nickname(data, SSL_SET_OPTION(issuercert)); ++ char *nickname = dup_nickname(data, SSL_CONN_CONFIG(issuercert)); + if(nickname) { + /* we support only nicknames in case of issuercert for now */ + ret = check_issuer_cert(BACKEND->handle, nickname); +diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c +index 726ff6e..23f9ce0 100644 +--- a/lib/vtls/openssl.c ++++ b/lib/vtls/openssl.c +@@ -422,12 +422,23 @@ static int ossl_get_ssl_conn_index(void) + */ + static int ossl_get_ssl_sockindex_index(void) + { +- static int ssl_ex_data_sockindex_index = -1; +- if(ssl_ex_data_sockindex_index < 0) { +- ssl_ex_data_sockindex_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, +- NULL); ++ static int sockindex_index = -1; ++ if(sockindex_index < 0) { ++ sockindex_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); + } +- return ssl_ex_data_sockindex_index; ++ return sockindex_index; ++} ++ ++/* Return an extra data index for proxy boolean. ++ * This index can be used with SSL_get_ex_data() and SSL_set_ex_data(). ++ */ ++static int ossl_get_proxy_index(void) ++{ ++ static int proxy_index = -1; ++ if(proxy_index < 0) { ++ proxy_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); ++ } ++ return proxy_index; + } + + static int passwd_callback(char *buf, int num, int encrypting, +@@ -1025,6 +1036,21 @@ static int Curl_ossl_init(void) + char *keylog_file_name; + #endif + ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \ ++ !defined(LIBRESSL_VERSION_NUMBER) ++ const uint64_t flags = ++#ifdef OPENSSL_INIT_ENGINE_ALL_BUILTIN ++ /* not present in BoringSSL */ ++ OPENSSL_INIT_ENGINE_ALL_BUILTIN | ++#endif ++#ifdef CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG ++ OPENSSL_INIT_NO_LOAD_CONFIG | ++#else ++ OPENSSL_INIT_LOAD_CONFIG | ++#endif ++ 0; ++ OPENSSL_init_ssl(flags, NULL); ++#else + OPENSSL_load_builtin_modules(); + + #ifdef USE_OPENSSL_ENGINE +@@ -1043,10 +1069,6 @@ static int Curl_ossl_init(void) + CONF_MFLAGS_IGNORE_MISSING_FILE); + #endif + +-#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \ +- !defined(LIBRESSL_VERSION_NUMBER) +- /* OpenSSL 1.1.0+ takes care of initialization itself */ +-#else + /* Lets get nice error messages */ + SSL_load_error_strings(); + +@@ -1079,7 +1101,8 @@ static int Curl_ossl_init(void) + #endif + + /* Initialize the extra data indexes */ +- if(ossl_get_ssl_conn_index() < 0 || ossl_get_ssl_sockindex_index() < 0) ++ if(ossl_get_ssl_conn_index() < 0 || ossl_get_ssl_sockindex_index() < 0 || ++ ossl_get_proxy_index() < 0) + return 0; + + return 1; +@@ -1717,6 +1740,11 @@ static CURLcode verifystatus(struct connectdata *conn, + OCSP_BASICRESP *br = NULL; + X509_STORE *st = NULL; + STACK_OF(X509) *ch = NULL; ++ X509 *cert; ++ OCSP_CERTID *id = NULL; ++ int cert_status, crl_reason; ++ ASN1_GENERALIZEDTIME *rev, *thisupd, *nextupd; ++ int ret; + + long len = SSL_get_tlsext_status_ocsp_resp(BACKEND->handle, &status); + +@@ -1785,43 +1813,63 @@ static CURLcode verifystatus(struct connectdata *conn, + goto end; + } + +- for(i = 0; i < OCSP_resp_count(br); i++) { +- int cert_status, crl_reason; +- OCSP_SINGLERESP *single = NULL; +- +- ASN1_GENERALIZEDTIME *rev, *thisupd, *nextupd; ++ /* Compute the certificate's ID */ ++ cert = SSL_get_peer_certificate(BACKEND->handle); ++ if(!cert) { ++ failf(data, "Error getting peer certficate"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- single = OCSP_resp_get0(br, i); +- if(!single) +- continue; ++ for(i = 0; i < sk_X509_num(ch); i++) { ++ X509 *issuer = sk_X509_value(ch, i); ++ if(X509_check_issued(issuer, cert) == X509_V_OK) { ++ id = OCSP_cert_to_id(EVP_sha1(), cert, issuer); ++ break; ++ } ++ } ++ X509_free(cert); + +- cert_status = OCSP_single_get0_status(single, &crl_reason, &rev, +- &thisupd, &nextupd); ++ if(!id) { ++ failf(data, "Error computing OCSP ID"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)) { +- failf(data, "OCSP response has expired"); +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; +- } ++ /* Find the single OCSP response corresponding to the certificate ID */ ++ ret = OCSP_resp_find_status(br, id, &cert_status, &crl_reason, &rev, ++ &thisupd, &nextupd); ++ OCSP_CERTID_free(id); ++ if(ret != 1) { ++ failf(data, "Could not find certificate ID in OCSP response"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- infof(data, "SSL certificate status: %s (%d)\n", +- OCSP_cert_status_str(cert_status), cert_status); ++ /* Validate the corresponding single OCSP response */ ++ if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)) { ++ failf(data, "OCSP response has expired"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- switch(cert_status) { +- case V_OCSP_CERTSTATUS_GOOD: +- break; ++ infof(data, "SSL certificate status: %s (%d)\n", ++ OCSP_cert_status_str(cert_status), cert_status); + +- case V_OCSP_CERTSTATUS_REVOKED: +- result = CURLE_SSL_INVALIDCERTSTATUS; ++ switch(cert_status) { ++ case V_OCSP_CERTSTATUS_GOOD: ++ break; + +- failf(data, "SSL certificate revocation reason: %s (%d)", +- OCSP_crl_reason_str(crl_reason), crl_reason); +- goto end; ++ case V_OCSP_CERTSTATUS_REVOKED: ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ failf(data, "SSL certificate revocation reason: %s (%d)", ++ OCSP_crl_reason_str(crl_reason), crl_reason); ++ goto end; + +- case V_OCSP_CERTSTATUS_UNKNOWN: +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; +- } ++ case V_OCSP_CERTSTATUS_UNKNOWN: ++ default: ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; + } + + end: +@@ -2342,8 +2390,10 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + curl_socket_t *sockindex_ptr; + int connectdata_idx = ossl_get_ssl_conn_index(); + int sockindex_idx = ossl_get_ssl_sockindex_index(); ++ int proxy_idx = ossl_get_proxy_index(); ++ bool isproxy; + +- if(connectdata_idx < 0 || sockindex_idx < 0) ++ if(connectdata_idx < 0 || sockindex_idx < 0 || proxy_idx < 0) + return 0; + + conn = (struct connectdata*) SSL_get_ex_data(ssl, connectdata_idx); +@@ -2356,13 +2406,18 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + sockindex_ptr = (curl_socket_t*) SSL_get_ex_data(ssl, sockindex_idx); + sockindex = (int)(sockindex_ptr - conn->sock); + ++ isproxy = SSL_get_ex_data(ssl, proxy_idx) ? TRUE : FALSE; ++ + if(SSL_SET_OPTION(primary.sessionid)) { + bool incache; + void *old_ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, +- sockindex)); ++ if(isproxy) ++ incache = FALSE; ++ else ++ incache = !(Curl_ssl_getsessionid(conn, isproxy, ++ &old_ssl_sessionid, NULL, sockindex)); + if(incache) { + if(old_ssl_sessionid != ssl_sessionid) { + infof(data, "old SSL session ID is stale, removing\n"); +@@ -2372,7 +2427,7 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + } + + if(!incache) { +- if(!Curl_ssl_addsessionid(conn, ssl_sessionid, ++ if(!Curl_ssl_addsessionid(conn, isproxy, ssl_sessionid, + 0 /* unknown size */, sockindex)) { + /* the session has been put into the session cache */ + res = 1; +@@ -2411,14 +2466,14 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + &data->set.proxy_ssl.certverifyresult : &data->set.ssl.certverifyresult; + const long int ssl_version = SSL_CONN_CONFIG(version); + #ifdef USE_TLS_SRP +- const enum CURL_TLSAUTH ssl_authtype = SSL_SET_OPTION(authtype); ++ const enum CURL_TLSAUTH ssl_authtype = SSL_SET_OPTION(primary.authtype); + #endif + char * const ssl_cert = SSL_SET_OPTION(cert); + const char * const ssl_cert_type = SSL_SET_OPTION(cert_type); + const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile); + const char * const ssl_capath = SSL_CONN_CONFIG(CApath); + const bool verifypeer = SSL_CONN_CONFIG(verifypeer); +- const char * const ssl_crlfile = SSL_SET_OPTION(CRLfile); ++ const char * const ssl_crlfile = SSL_SET_OPTION(primary.CRLfile); + char error_buffer[256]; + + DEBUGASSERT(ssl_connect_1 == connssl->connecting_state); +@@ -2697,15 +2752,15 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + + #ifdef USE_TLS_SRP + if(ssl_authtype == CURL_TLSAUTH_SRP) { +- char * const ssl_username = SSL_SET_OPTION(username); +- ++ char * const ssl_username = SSL_SET_OPTION(primary.username); ++ char * const ssl_password = SSL_SET_OPTION(primary.password); + infof(data, "Using TLS-SRP username: %s\n", ssl_username); + + if(!SSL_CTX_set_srp_username(BACKEND->ctx, ssl_username)) { + failf(data, "Unable to set SRP user name"); + return CURLE_BAD_FUNCTION_ARGUMENT; + } +- if(!SSL_CTX_set_srp_password(BACKEND->ctx, SSL_SET_OPTION(password))) { ++ if(!SSL_CTX_set_srp_password(BACKEND->ctx, ssl_password)) { + failf(data, "failed setting SRP password"); + return CURLE_BAD_FUNCTION_ARGUMENT; + } +@@ -2869,16 +2924,25 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + void *ssl_sessionid = NULL; + int connectdata_idx = ossl_get_ssl_conn_index(); + int sockindex_idx = ossl_get_ssl_sockindex_index(); ++ int proxy_idx = ossl_get_proxy_index(); + +- if(connectdata_idx >= 0 && sockindex_idx >= 0) { ++ if(connectdata_idx >= 0 && sockindex_idx >= 0 && proxy_idx >= 0) { + /* Store the data needed for the "new session" callback. + * The sockindex is stored as a pointer to an array element. */ + SSL_set_ex_data(BACKEND->handle, connectdata_idx, conn); + SSL_set_ex_data(BACKEND->handle, sockindex_idx, conn->sock + sockindex); ++#ifndef CURL_DISABLE_PROXY ++ SSL_set_ex_data(BACKEND->handle, proxy_idx, SSL_IS_PROXY() ? (void *) 1: ++ NULL); ++#else ++ SSL_set_ex_data(BACKEND->handle, proxy_idx, NULL); ++#endif ++ + } + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + Curl_ssl_sessionid_unlock(conn); +@@ -3539,7 +3603,7 @@ static CURLcode servercert(struct connectdata *conn, + deallocating the certificate. */ + + /* e.g. match issuer name with provided issuer certificate */ +- if(SSL_SET_OPTION(issuercert)) { ++ if(SSL_CONN_CONFIG(issuercert)) { + fp = BIO_new(BIO_s_file()); + if(fp == NULL) { + failf(data, +@@ -3552,10 +3616,10 @@ static CURLcode servercert(struct connectdata *conn, + return CURLE_OUT_OF_MEMORY; + } + +- if(BIO_read_filename(fp, SSL_SET_OPTION(issuercert)) <= 0) { ++ if(BIO_read_filename(fp, SSL_CONN_CONFIG(issuercert)) <= 0) { + if(strict) + failf(data, "SSL: Unable to open issuer cert (%s)", +- SSL_SET_OPTION(issuercert)); ++ SSL_CONN_CONFIG(issuercert)); + BIO_free(fp); + X509_free(BACKEND->server_cert); + BACKEND->server_cert = NULL; +@@ -3566,7 +3630,7 @@ static CURLcode servercert(struct connectdata *conn, + if(!issuer) { + if(strict) + failf(data, "SSL: Unable to read issuer cert (%s)", +- SSL_SET_OPTION(issuercert)); ++ SSL_CONN_CONFIG(issuercert)); + BIO_free(fp); + X509_free(issuer); + X509_free(BACKEND->server_cert); +@@ -3577,7 +3641,7 @@ static CURLcode servercert(struct connectdata *conn, + if(X509_check_issued(issuer, BACKEND->server_cert) != X509_V_OK) { + if(strict) + failf(data, "SSL: Certificate issuer check failed (%s)", +- SSL_SET_OPTION(issuercert)); ++ SSL_CONN_CONFIG(issuercert)); + BIO_free(fp); + X509_free(issuer); + X509_free(BACKEND->server_cert); +@@ -3586,7 +3650,7 @@ static CURLcode servercert(struct connectdata *conn, + } + + infof(data, " SSL certificate issuer check ok (%s)\n", +- SSL_SET_OPTION(issuercert)); ++ SSL_CONN_CONFIG(issuercert)); + BIO_free(fp); + X509_free(issuer); + } +diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c +index dc58ed0..f0aa727 100644 +--- a/lib/vtls/schannel.c ++++ b/lib/vtls/schannel.c +@@ -497,7 +497,8 @@ schannel_connect_step1(struct connectdata *conn, int sockindex) + /* check for an existing re-usable credential handle */ + if(SSL_SET_OPTION(primary.sessionid)) { + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ (void **)&old_cred, NULL, sockindex)) { + BACKEND->cred = old_cred; + DEBUGF(infof(data, "schannel: re-using existing credential handle\n")); + +@@ -1203,8 +1204,9 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + struct ssl_connect_data *connssl = &conn->ssl[sockindex]; + SECURITY_STATUS sspi_status = SEC_E_OK; + CERT_CONTEXT *ccert_context = NULL; ++ bool isproxy = SSL_IS_PROXY(); + #ifdef DEBUGBUILD +- const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name : ++ const char * const hostname = isproxy ? conn->http_proxy.host.name : + conn->host.name; + #endif + #ifdef HAS_ALPN +@@ -1278,7 +1280,7 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + struct curl_schannel_cred *old_cred = NULL; + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, isproxy, (void **)&old_cred, NULL, + sockindex)); + if(incache) { + if(old_cred != BACKEND->cred) { +@@ -1290,7 +1292,7 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + } + } + if(!incache) { +- result = Curl_ssl_addsessionid(conn, (void *)BACKEND->cred, ++ result = Curl_ssl_addsessionid(conn, isproxy, (void *)BACKEND->cred, + sizeof(struct curl_schannel_cred), + sockindex); + if(result) { +diff --git a/lib/vtls/sectransp.c b/lib/vtls/sectransp.c +index 4eece89..1c05607 100644 +--- a/lib/vtls/sectransp.c ++++ b/lib/vtls/sectransp.c +@@ -1376,7 +1376,8 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile); + const bool verifypeer = SSL_CONN_CONFIG(verifypeer); + char * const ssl_cert = SSL_SET_OPTION(cert); +- const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name : ++ bool isproxy = SSL_IS_PROXY(); ++ const char * const hostname = isproxy ? conn->http_proxy.host.name : + conn->host.name; + const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port; + #ifdef ENABLE_IPV6 +@@ -1584,7 +1585,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + + #ifdef USE_NGHTTP2 + if(data->set.httpversion >= CURL_HTTP_VERSION_2 && +- (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)) { ++ (!isproxy || !conn->bits.tunnel_proxy)) { + CFArrayAppendValue(alpnArr, CFSTR(NGHTTP2_PROTO_VERSION_ID)); + infof(data, "ALPN, offering %s\n", NGHTTP2_PROTO_VERSION_ID); + } +@@ -1916,7 +1917,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + size_t ssl_sessionid_len; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, (void **)&ssl_sessionid, ++ if(!Curl_ssl_getsessionid(conn, isproxy, (void **)&ssl_sessionid, + &ssl_sessionid_len, sockindex)) { + /* we got a session id, use it! */ + err = SSLSetPeerID(BACKEND->ssl_ctx, ssl_sessionid, ssl_sessionid_len); +@@ -1944,7 +1945,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + return CURLE_SSL_CONNECT_ERROR; + } + +- result = Curl_ssl_addsessionid(conn, ssl_sessionid, ssl_sessionid_len, ++ result = Curl_ssl_addsessionid(conn, isproxy, ssl_sessionid, ssl_sessionid_len, + sockindex); + Curl_ssl_sessionid_unlock(conn); + if(result) { +diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c +index c493b15..557c8d3 100644 +--- a/lib/vtls/vtls.c ++++ b/lib/vtls/vtls.c +@@ -82,22 +82,40 @@ + else \ + dest->var = NULL; + ++static bool safecmp(char *a, char *b) ++{ ++ if(a && b) ++ return !strcmp(a, b); ++ else if(!a && !b) ++ return TRUE; /* match */ ++ return FALSE; /* no match */ ++} ++ ++ + bool + Curl_ssl_config_matches(struct ssl_primary_config* data, + struct ssl_primary_config* needle) + { + if((data->version == needle->version) && + (data->version_max == needle->version_max) && ++ (data->ssl_options == needle->ssl_options) && + (data->verifypeer == needle->verifypeer) && + (data->verifyhost == needle->verifyhost) && + (data->verifystatus == needle->verifystatus) && +- Curl_safe_strcasecompare(data->CApath, needle->CApath) && +- Curl_safe_strcasecompare(data->CAfile, needle->CAfile) && +- Curl_safe_strcasecompare(data->clientcert, needle->clientcert) && +- Curl_safe_strcasecompare(data->random_file, needle->random_file) && +- Curl_safe_strcasecompare(data->egdsocket, needle->egdsocket) && ++ safecmp(data->CApath, needle->CApath) && ++ safecmp(data->CAfile, needle->CAfile) && ++ safecmp(data->issuercert, needle->issuercert) && ++ safecmp(data->clientcert, needle->clientcert) && ++ safecmp(data->random_file, needle->random_file) && ++ safecmp(data->egdsocket, needle->egdsocket) && ++#ifdef USE_TLS_SRP ++ Curl_safecmp(data->username, needle->username) && ++ Curl_safecmp(data->password, needle->password) && ++ (data->authtype == needle->authtype) && ++#endif + Curl_safe_strcasecompare(data->cipher_list, needle->cipher_list) && + Curl_safe_strcasecompare(data->cipher_list13, needle->cipher_list13) && ++ Curl_safe_strcasecompare(data->CRLfile, needle->CRLfile) && + Curl_safe_strcasecompare(data->pinned_key, needle->pinned_key)) + return TRUE; + +@@ -114,15 +132,25 @@ Curl_clone_primary_ssl_config(struct ssl_primary_config *source, + dest->verifyhost = source->verifyhost; + dest->verifystatus = source->verifystatus; + dest->sessionid = source->sessionid; ++ dest->ssl_options = source->ssl_options; ++#ifdef USE_TLS_SRP ++ dest->authtype = source->authtype; ++#endif + + CLONE_STRING(CApath); + CLONE_STRING(CAfile); ++ CLONE_STRING(issuercert); + CLONE_STRING(clientcert); + CLONE_STRING(random_file); + CLONE_STRING(egdsocket); + CLONE_STRING(cipher_list); + CLONE_STRING(cipher_list13); + CLONE_STRING(pinned_key); ++ CLONE_STRING(CRLfile); ++#ifdef USE_TLS_SRP ++ CLONE_STRING(username); ++ CLONE_STRING(password); ++#endif + + return TRUE; + } +@@ -131,12 +159,18 @@ void Curl_free_primary_ssl_config(struct ssl_primary_config* sslc) + { + Curl_safefree(sslc->CApath); + Curl_safefree(sslc->CAfile); ++ Curl_safefree(sslc->issuercert); + Curl_safefree(sslc->clientcert); + Curl_safefree(sslc->random_file); + Curl_safefree(sslc->egdsocket); + Curl_safefree(sslc->cipher_list); + Curl_safefree(sslc->cipher_list13); + Curl_safefree(sslc->pinned_key); ++ Curl_safefree(sslc->CRLfile); ++#ifdef USE_TLS_SRP ++ Curl_safefree(sslc->username); ++ Curl_safefree(sslc->password); ++#endif + } + + #ifdef USE_SSL +@@ -305,6 +339,7 @@ void Curl_ssl_sessionid_unlock(struct connectdata *conn) + * there's one suitable, it is provided. Returns TRUE when no entry matched. + */ + bool Curl_ssl_getsessionid(struct connectdata *conn, ++ const bool isProxy, + void **ssl_sessionid, + size_t *idsize, /* set 0 if unknown */ + int sockindex) +@@ -315,7 +350,6 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + long *general_age; + bool no_match = TRUE; + +- const bool isProxy = CONNECT_PROXY_SSL(); + struct ssl_primary_config * const ssl_config = isProxy ? + &conn->proxy_ssl_config : + &conn->ssl_config; +@@ -324,6 +358,11 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + int port = isProxy ? (int)conn->port : conn->remote_port; + *ssl_sessionid = NULL; + ++#ifdef CURL_DISABLE_PROXY ++ if(isProxy) ++ return TRUE; ++#endif ++ + DEBUGASSERT(SSL_SET_OPTION(primary.sessionid)); + + if(!SSL_SET_OPTION(primary.sessionid)) +@@ -411,6 +450,7 @@ void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid) + * later on. + */ + CURLcode Curl_ssl_addsessionid(struct connectdata *conn, ++ bool isProxy, + void *ssl_sessionid, + size_t idsize, + int sockindex) +@@ -423,7 +463,6 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn, + char *clone_conn_to_host; + int conn_to_port; + long *general_age; +- const bool isProxy = CONNECT_PROXY_SSL(); + struct ssl_primary_config * const ssl_config = isProxy ? + &conn->proxy_ssl_config : + &conn->ssl_config; +diff --git a/lib/vtls/vtls.h b/lib/vtls/vtls.h +index 976cc43..9fed5a0 100644 +--- a/lib/vtls/vtls.h ++++ b/lib/vtls/vtls.h +@@ -203,6 +203,7 @@ void Curl_ssl_sessionid_unlock(struct connectdata *conn); + * under sessionid mutex). + */ + bool Curl_ssl_getsessionid(struct connectdata *conn, ++ const bool isproxy, + void **ssl_sessionid, + size_t *idsize, /* set 0 if unknown */ + int sockindex); +@@ -212,6 +213,7 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + * object with cache (e.g. incrementing refcount on success) + */ + CURLcode Curl_ssl_addsessionid(struct connectdata *conn, ++ const bool isProxy, + void *ssl_sessionid, + size_t idsize, + int sockindex); +diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c +index 890bcbf..c772bd5 100644 +--- a/lib/vtls/wolfssl.c ++++ b/lib/vtls/wolfssl.c +@@ -392,7 +392,8 @@ wolfssl_connect_step1(struct connectdata *conn, + void *ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + char error_buffer[WOLFSSL_MAX_ERROR_SZ]; +@@ -618,9 +619,10 @@ wolfssl_connect_step3(struct connectdata *conn, + void *old_ssl_sessionid = NULL; + + our_ssl_sessionid = SSL_get_session(BACKEND->handle); ++ bool isproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, NULL, + sockindex)); + if(incache) { + if(old_ssl_sessionid != our_ssl_sessionid) { +@@ -631,7 +633,7 @@ wolfssl_connect_step3(struct connectdata *conn, + } + + if(!incache) { +- result = Curl_ssl_addsessionid(conn, our_ssl_sessionid, ++ result = Curl_ssl_addsessionid(conn, isproxy, our_ssl_sessionid, + 0 /* unknown size */, sockindex); + if(result) { + Curl_ssl_sessionid_unlock(conn); +diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c +index 77224ad..e0784c6 100644 +--- a/src/tool_cb_hdr.c ++++ b/src/tool_cb_hdr.c +@@ -188,25 +188,11 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata) + filename = parse_filename(p, len); + if(filename) { + if(outs->stream) { +- int rc; +- /* already opened and possibly written to */ +- if(outs->fopened) +- fclose(outs->stream); +- outs->stream = NULL; +- +- /* rename the initial file name to the new file name */ +- rc = rename(outs->filename, filename); +- if(rc != 0) { +- warnf(outs->config->global, "Failed to rename %s -> %s: %s\n", +- outs->filename, filename, strerror(errno)); +- } +- if(outs->alloc_filename) +- Curl_safefree(outs->filename); +- if(rc != 0) { +- free(filename); +- return failure; +- } ++ /* indication of problem, get out! */ ++ free(filename); ++ return failure; + } ++ + outs->is_cd_filename = TRUE; + outs->s_isreg = TRUE; + outs->fopened = FALSE; +diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c +index f802a5a..d492b58 100644 +--- a/src/tool_cfgable.c ++++ b/src/tool_cfgable.c +@@ -44,6 +44,7 @@ void config_init(struct OperationConfig* config) + config->tcp_nodelay = TRUE; /* enabled by default */ + config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT; + config->http09_allowed = FALSE; ++ config->ftp_skip_ip = TRUE; + } + + static void free_config_fields(struct OperationConfig *config) +diff --git a/src/tool_getparam.c b/src/tool_getparam.c +index 8df6e5e..8191ed5 100644 +--- a/src/tool_getparam.c ++++ b/src/tool_getparam.c +@@ -1800,6 +1800,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ + } + break; + case 'i': ++ if(config->content_disposition) { ++ warnf(global, ++ "--include and --remote-header-name cannot be combined.\n"); ++ return PARAM_BAD_USE; ++ } + config->show_headers = toggle; /* show the headers as well in the + general output stream */ + break; +diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc +index 09cb057..52bdaec 100644 +--- a/tests/data/Makefile.inc ++++ b/tests/data/Makefile.inc +@@ -111,6 +111,11 @@ test936 test937 test938 test939 test940 test941 test942 test943 test944 \ + test945 test946 test947 test948 test949 test950 test951 test952 test953 \ + test954 \ + \ ++test973 test974 test975 test976 \ ++test980 test981 test982 test983 \ ++\ ++test984 test985 test986 \ ++\ + test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 \ + test1008 test1009 test1010 test1011 test1012 test1013 test1014 test1015 \ + test1016 test1017 test1018 test1019 test1020 test1021 test1022 test1023 \ +@@ -131,7 +136,7 @@ test1128 test1129 test1130 test1131 test1132 test1133 test1134 test1135 \ + test1136 test1137 test1138 test1139 test1140 test1141 test1142 test1143 \ + test1144 test1145 test1146 test1147 test1148 test1149 test1150 test1151 \ + test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 \ +-test1160 test1161 test1162 test1163 test1164 test1165 test1166 \ ++test1160 test1161 test1162 test1163 test1164 test1165 test1166 test1168 \ + test1170 test1171 test1172 test1173 test1174 test1175 \ + \ + test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \ +diff --git a/tests/data/test1168 b/tests/data/test1168 +new file mode 100644 +index 0000000..283e91e +--- /dev/null ++++ b/tests/data/test1168 +@@ -0,0 +1,78 @@ ++ ++ ++ ++HTTP ++HTTP GET ++followlocation ++ ++ ++# Server-side ++ ++ ++HTTP/1.1 301 This is a weirdo text message swsclose ++Date: Thu, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Location: /data/11680002.txt ++Connection: close ++ ++This server reply is for testing a simple Location: following ++ ++ ++ ++HTTP/1.1 200 Followed here fine swsclose ++Date: Thu, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 52 ++ ++If this is received, the location following worked ++ ++ ++ ++HTTP/1.1 301 This is a weirdo text message swsclose ++Date: Thu, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Location: /data/11680002.txt ++Connection: close ++ ++HTTP/1.1 200 Followed here fine swsclose ++Date: Thu, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 52 ++ ++If this is received, the location following worked ++ ++ ++ ++ ++# Client-side ++ ++ ++http ++ ++ ++HTTP redirect with credentials using # in user and password ++ ++ ++http://%HOSTIP:%HTTPPORT/want/1168 -L -u "catmai#d:#DZaRJYrixKE*gFY" ++ ++ ++ ++# Verify data after the test has been "shot" ++ ++ ++^User-Agent:.* ++ ++ ++GET /want/1168 HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++Authorization: Basic Y2F0bWFpI2Q6I0RaYVJKWXJpeEtFKmdGWQ== ++Accept: */* ++ ++GET /data/11680002.txt HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++Authorization: Basic Y2F0bWFpI2Q6I0RaYVJKWXJpeEtFKmdGWQ== ++Accept: */* ++ ++ ++ ++ +diff --git a/tests/data/test1400 b/tests/data/test1400 +index c0d409b..ade50d4 100644 +--- a/tests/data/test1400 ++++ b/tests/data/test1400 +@@ -76,6 +76,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1401 b/tests/data/test1401 +index ec3b25c..a2e9ef2 100644 +--- a/tests/data/test1401 ++++ b/tests/data/test1401 +@@ -90,6 +90,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_COOKIE, "chocolate=chip"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(hnd, CURLOPT_PROTOCOLS, (long)CURLPROTO_FILE | + (long)CURLPROTO_FTP | +diff --git a/tests/data/test1402 b/tests/data/test1402 +index bf7eb7b..99d4b70 100644 +--- a/tests/data/test1402 ++++ b/tests/data/test1402 +@@ -81,6 +81,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1403 b/tests/data/test1403 +index 731d274..90f9b4e 100644 +--- a/tests/data/test1403 ++++ b/tests/data/test1403 +@@ -76,6 +76,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1404 b/tests/data/test1404 +index d3c66a9..d351c3e 100644 +--- a/tests/data/test1404 ++++ b/tests/data/test1404 +@@ -147,6 +147,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1405 b/tests/data/test1405 +index dcc8f80..d1ebb7c 100644 +--- a/tests/data/test1405 ++++ b/tests/data/test1405 +@@ -89,6 +89,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_POSTQUOTE, slist2); + curl_easy_setopt(hnd, CURLOPT_PREQUOTE, slist3); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1406 b/tests/data/test1406 +index 8803c84..31db82a 100644 +--- a/tests/data/test1406 ++++ b/tests/data/test1406 +@@ -79,6 +79,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_URL, "smtp://%HOSTIP:%SMTPPORT/1406"); + curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(hnd, CURLOPT_MAIL_FROM, "sender@example.com"); + curl_easy_setopt(hnd, CURLOPT_MAIL_RCPT, slist1); +diff --git a/tests/data/test1407 b/tests/data/test1407 +index 917a5de..d329509 100644 +--- a/tests/data/test1407 ++++ b/tests/data/test1407 +@@ -62,6 +62,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_DIRLISTONLY, 1L); + curl_easy_setopt(hnd, CURLOPT_USERPWD, "user:secret"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1420 b/tests/data/test1420 +index 03c4584..c1ba190 100644 +--- a/tests/data/test1420 ++++ b/tests/data/test1420 +@@ -67,6 +67,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_URL, "imap://%HOSTIP:%IMAPPORT/1420/;MAILINDEX=1"); + curl_easy_setopt(hnd, CURLOPT_USERPWD, "user:secret"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test973 b/tests/data/test973 +new file mode 100644 +index 0000000..e2f051d +--- /dev/null ++++ b/tests/data/test973 +@@ -0,0 +1,88 @@ ++ ++ ++ ++HTTP ++FTP ++--location ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: ftp://127.0.0.1:8992/a/path/9730002 ++ ++ ++ ++data ++ to ++ see ++that FTP ++works ++ so does it? ++ ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: ftp://127.0.0.1:8992/a/path/9730002 ++ ++data ++ to ++ see ++that FTP ++works ++ so does it? ++ ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ftp ++ ++ ++HTTP with auth redirected to FTP w/o auth ++ ++ ++http://%HOSTIP:%HTTPPORT/973 -L -u joe:secret ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++GET /973 HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++ ++USER anonymous ++PASS ftp@example.com ++PWD ++CWD a ++CWD path ++EPSV ++TYPE I ++SIZE 9730002 ++RETR 9730002 ++QUIT ++ ++ ++ +diff --git a/tests/data/test974 b/tests/data/test974 +new file mode 100644 +index 0000000..854200a +--- /dev/null ++++ b/tests/data/test974 +@@ -0,0 +1,87 @@ ++ ++ ++ ++HTTP ++--location ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: http://firsthost.974:9999/a/path/9740002 ++ ++ ++ ++HTTP/1.1 200 OK ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 4 ++Connection: close ++Content-Type: text/html ++ ++hey ++ ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: http://firsthost.974:9999/a/path/9740002 ++ ++HTTP/1.1 200 OK ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 4 ++Connection: close ++Content-Type: text/html ++ ++hey ++ ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ ++ ++HTTP with auth redirected to HTTP on a diff port w/o auth ++ ++ ++-x http://%HOSTIP:%HTTPPORT http://firsthost.974 -L -u joe:secret ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++GET http://firsthost.974/ HTTP/1.1 ++Host: firsthost.974 ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++Proxy-Connection: Keep-Alive ++ ++GET http://firsthost.974:9999/a/path/9740002 HTTP/1.1 ++Host: firsthost.974:9999 ++User-Agent: curl/7.68.0 ++Accept: */* ++Proxy-Connection: Keep-Alive ++ ++ ++ ++ +diff --git a/tests/data/test975 b/tests/data/test975 +new file mode 100644 +index 0000000..2ab23e9 +--- /dev/null ++++ b/tests/data/test975 +@@ -0,0 +1,88 @@ ++ ++ ++ ++HTTP ++FTP ++--location-trusted ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: ftp://127.0.0.1:8992/a/path/9750002 ++ ++ ++ ++data ++ to ++ see ++that FTP ++works ++ so does it? ++ ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: ftp://127.0.0.1:8992/a/path/9750002 ++ ++data ++ to ++ see ++that FTP ++works ++ so does it? ++ ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ftp ++ ++ ++HTTP with auth redirected to FTP allowing auth to continue ++ ++ ++http://%HOSTIP:%HTTPPORT/975 --location-trusted -u joe:secret ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++GET /975 HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++ ++USER joe ++PASS secret ++PWD ++CWD a ++CWD path ++EPSV ++TYPE I ++SIZE 9750002 ++RETR 9750002 ++QUIT ++ ++ ++ +diff --git a/tests/data/test976 b/tests/data/test976 +new file mode 100644 +index 0000000..65d51ce +--- /dev/null ++++ b/tests/data/test976 +@@ -0,0 +1,88 @@ ++ ++ ++ ++HTTP ++--location-trusted ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: http://firsthost.976:9999/a/path/9760002 ++ ++ ++ ++HTTP/1.1 200 OK ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 4 ++Connection: close ++Content-Type: text/html ++ ++hey ++ ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: http://firsthost.976:9999/a/path/9760002 ++ ++HTTP/1.1 200 OK ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 4 ++Connection: close ++Content-Type: text/html ++ ++hey ++ ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ ++ ++HTTP with auth redirected to HTTP on a diff port --location-trusted ++ ++ ++-x http://%HOSTIP:%HTTPPORT http://firsthost.976 --location-trusted -u joe:secret ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++GET http://firsthost.976/ HTTP/1.1 ++Host: firsthost.976 ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++Proxy-Connection: Keep-Alive ++ ++GET http://firsthost.976:9999/a/path/9760002 HTTP/1.1 ++Host: firsthost.976:9999 ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++Proxy-Connection: Keep-Alive ++ ++ ++ ++ +diff --git a/tests/data/test980 b/tests/data/test980 +new file mode 100644 +index 0000000..97567f8 +--- /dev/null ++++ b/tests/data/test980 +@@ -0,0 +1,52 @@ ++ ++ ++ ++SMTP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++CAPA STARTTLS ++AUTH PLAIN ++REPLY STARTTLS 454 currently unavailable\r\n235 Authenticated\r\n250 2.1.0 Sender ok\r\n250 2.1.5 Recipient ok\r\n354 Enter mail\r\n250 2.0.0 Accepted ++REPLY AUTH 535 5.7.8 Authentication credentials invalid ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++smtp ++ ++ ++SMTP STARTTLS pipelined server response ++ ++ ++mail body ++ ++ ++smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -u user:secret --ssl --sasl-ir -T - ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 8 is CURLE_WEIRD_SERVER_REPLY ++ ++8 ++ ++ ++EHLO %TESTNUMBER ++STARTTLS ++ ++ ++ +diff --git a/tests/data/test981 b/tests/data/test981 +new file mode 100644 +index 0000000..2b98ce4 +--- /dev/null ++++ b/tests/data/test981 +@@ -0,0 +1,59 @@ ++ ++ ++ ++IMAP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++CAPA STARTTLS ++REPLY STARTTLS A002 BAD currently unavailable\r\nA003 OK Authenticated\r\nA004 OK Accepted ++REPLY LOGIN A003 BAD Authentication credentials invalid ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++imap ++ ++ ++IMAP STARTTLS pipelined server response ++ ++ ++imap://%HOSTIP:%IMAPPORT/%TESTNUMBER -T log/upload%TESTNUMBER -u user:secret --ssl ++ ++ ++Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST) ++From: Fred Foobar ++Subject: afternoon meeting ++To: joe@example.com ++Message-Id: ++MIME-Version: 1.0 ++Content-Type: TEXT/PLAIN; CHARSET=US-ASCII ++ ++Hello Joe, do you think we can meet at 3:30 tomorrow? ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 8 is CURLE_WEIRD_SERVER_REPLY ++ ++8 ++ ++ ++A001 CAPABILITY ++A002 STARTTLS ++ ++ ++ +diff --git a/tests/data/test982 b/tests/data/test982 +new file mode 100644 +index 0000000..9e07cc0 +--- /dev/null ++++ b/tests/data/test982 +@@ -0,0 +1,57 @@ ++ ++ ++ ++POP3 ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++CAPA STLS USER ++REPLY STLS -ERR currently unavailable\r\n+OK user accepted\r\n+OK authenticated ++REPLY PASS -ERR Authentication credentials invalid ++ ++ ++From: me@somewhere ++To: fake@nowhere ++ ++body ++ ++-- ++ yours sincerely ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++pop3 ++ ++ ++POP3 STARTTLS pipelined server response ++ ++ ++pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u user:secret --ssl ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 8 is CURLE_WEIRD_SERVER_REPLY ++ ++8 ++ ++ ++CAPA ++STLS ++ ++ ++ +diff --git a/tests/data/test983 b/tests/data/test983 +new file mode 100644 +index 0000000..300ec45 +--- /dev/null ++++ b/tests/data/test983 +@@ -0,0 +1,52 @@ ++ ++ ++ ++FTP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++REPLY AUTH 500 unknown command\r\n500 unknown command\r\n331 give password\r\n230 Authenticated\r\n257 "/"\r\n200 OK\r\n200 OK\r\n200 OK\r\n226 Transfer complete ++REPLY PASS 530 Login incorrect ++ ++ ++ ++# Client-side ++ ++ ++SSL ++ ++ ++ftp ++ ++ ++FTP STARTTLS pipelined server response ++ ++ ++data ++ to ++ see ++that FTPS ++works ++ so does it? ++ ++ ++--ssl --ftp-ssl-control ftp://%HOSTIP:%FTPPORT/%TESTNUMBER -T log/test%TESTNUMBER.txt -u user:secret -P %CLIENTIP ++ ++ ++ ++# Verify data after the test has been "shot" ++ ++# 8 is CURLE_WEIRD_SERVER_REPLY ++ ++8 ++ ++ ++AUTH SSL ++ ++ ++ +diff --git a/tests/data/test984 b/tests/data/test984 +new file mode 100644 +index 0000000..e573f23 +--- /dev/null ++++ b/tests/data/test984 +@@ -0,0 +1,56 @@ ++ ++ ++ ++IMAP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++REPLY CAPABILITY A001 BAD Not implemented ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++imap ++ ++ ++IMAP require STARTTLS with failing capabilities ++ ++ ++imap://%HOSTIP:%IMAPPORT/%TESTNUMBER -T log/upload%TESTNUMBER -u user:secret --ssl-reqd ++ ++ ++Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST) ++From: Fred Foobar ++Subject: afternoon meeting ++To: joe@example.com ++Message-Id: ++MIME-Version: 1.0 ++Content-Type: TEXT/PLAIN; CHARSET=US-ASCII ++ ++Hello Joe, do you think we can meet at 3:30 tomorrow? ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 64 is CURLE_USE_SSL_FAILED ++ ++64 ++ ++ ++A001 CAPABILITY ++ ++ ++ +diff --git a/tests/data/test985 b/tests/data/test985 +new file mode 100644 +index 0000000..d0db4aa +--- /dev/null ++++ b/tests/data/test985 +@@ -0,0 +1,54 @@ ++ ++ ++ ++POP3 ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++REPLY CAPA -ERR Not implemented ++ ++ ++From: me@somewhere ++To: fake@nowhere ++ ++body ++ ++-- ++ yours sincerely ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++pop3 ++ ++ ++POP3 require STARTTLS with failing capabilities ++ ++ ++pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u user:secret --ssl-reqd ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 64 is CURLE_USE_SSL_FAILED ++ ++64 ++ ++ ++CAPA ++ ++ ++ +diff --git a/tests/data/test986 b/tests/data/test986 +new file mode 100644 +index 0000000..a709437 +--- /dev/null ++++ b/tests/data/test986 +@@ -0,0 +1,53 @@ ++ ++ ++ ++FTP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++REPLY welcome 230 Welcome ++REPLY AUTH 500 unknown command ++ ++ ++ ++# Client-side ++ ++ ++SSL ++ ++ ++ftp ++ ++ ++FTP require STARTTLS while preauthenticated ++ ++ ++data ++ to ++ see ++that FTPS ++works ++ so does it? ++ ++ ++--ssl-reqd --ftp-ssl-control ftp://%HOSTIP:%FTPPORT/%TESTNUMBER -T log/test%TESTNUMBER.txt -u user:secret ++ ++ ++ ++# Verify data after the test has been "shot" ++ ++# 64 is CURLE_USE_SSL_FAILED ++ ++64 ++ ++ ++AUTH SSL ++AUTH TLS ++ ++ ++ diff --git a/debian/patches/0010-update-info.patch b/debian/patches/0010-update-info.patch new file mode 100644 index 0000000000000000000000000000000000000000..2d0e97161c5a6559031ebf327e6a6aa50b442de7 --- /dev/null +++ b/debian/patches/0010-update-info.patch @@ -0,0 +1,3358 @@ +From: luzhiping +Date: Mon, 22 Aug 2022 16:34:21 +0800 +Subject: update info + +--- + docs/cmdline-opts/ftp-skip-pasv-ip.d | 2 - + docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 | 8 +- + lib/conncache.c | 8 +- + lib/connect.c | 20 ++- + lib/content_encoding.c | 9 -- + lib/cookie.c | 29 ---- + lib/easy.c | 3 +- + lib/ftp.c | 227 +++++++++++++-------------- + lib/http.c | 34 ++-- + lib/imap.c | 28 ++-- + lib/krb5.c | 5 +- + lib/multi.c | 5 +- + lib/pop3.c | 37 ++--- + lib/setopt.c | 30 ++-- + lib/smtp.c | 4 - + lib/strcase.c | 10 -- + lib/strcase.h | 2 - + lib/telnet.c | 17 +- + lib/transfer.c | 70 +-------- + lib/url.c | 60 ++----- + lib/urldata.h | 40 ++--- + lib/vssh/ssh.h | 4 +- + lib/vtls/bearssl.c | 9 +- + lib/vtls/gtls.c | 51 +++--- + lib/vtls/mbedtls.c | 8 +- + lib/vtls/mesalink.c | 9 +- + lib/vtls/nss.c | 18 +-- + lib/vtls/openssl.c | 176 +++++++-------------- + lib/vtls/schannel.c | 10 +- + lib/vtls/sectransp.c | 9 +- + lib/vtls/vtls.c | 53 +------ + lib/vtls/vtls.h | 2 - + lib/vtls/wolfssl.c | 8 +- + src/tool_cb_hdr.c | 22 ++- + src/tool_cfgable.c | 1 - + src/tool_getparam.c | 5 - + tests/data/Makefile.inc | 7 +- + tests/data/test1168 | 78 --------- + tests/data/test1400 | 1 - + tests/data/test1401 | 1 - + tests/data/test1402 | 1 - + tests/data/test1403 | 1 - + tests/data/test1404 | 1 - + tests/data/test1405 | 1 - + tests/data/test1406 | 1 - + tests/data/test1407 | 1 - + tests/data/test1420 | 1 - + tests/data/test973 | 88 ----------- + tests/data/test974 | 87 ---------- + tests/data/test975 | 88 ----------- + tests/data/test976 | 88 ----------- + tests/data/test980 | 52 ------ + tests/data/test981 | 59 ------- + tests/data/test982 | 57 ------- + tests/data/test983 | 52 ------ + tests/data/test984 | 56 ------- + tests/data/test985 | 54 ------- + tests/data/test986 | 53 ------- + 58 files changed, 359 insertions(+), 1502 deletions(-) + delete mode 100644 tests/data/test1168 + delete mode 100644 tests/data/test973 + delete mode 100644 tests/data/test974 + delete mode 100644 tests/data/test975 + delete mode 100644 tests/data/test976 + delete mode 100644 tests/data/test980 + delete mode 100644 tests/data/test981 + delete mode 100644 tests/data/test982 + delete mode 100644 tests/data/test983 + delete mode 100644 tests/data/test984 + delete mode 100644 tests/data/test985 + delete mode 100644 tests/data/test986 + +diff --git a/docs/cmdline-opts/ftp-skip-pasv-ip.d b/docs/cmdline-opts/ftp-skip-pasv-ip.d +index 4be8b43..da6ab11 100644 +--- a/docs/cmdline-opts/ftp-skip-pasv-ip.d ++++ b/docs/cmdline-opts/ftp-skip-pasv-ip.d +@@ -9,6 +9,4 @@ to curl's PASV command when curl connects the data connection. Instead curl + will re-use the same IP address it already uses for the control + connection. + +-Since curl 7.74.0 this option is enabled by default. +- + This option has no effect if PORT, EPRT or EPSV is used instead of PASV. +diff --git a/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 b/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 +index d75204a..5f234b4 100644 +--- a/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 ++++ b/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 +@@ -5,7 +5,7 @@ + .\" * | (__| |_| | _ <| |___ + .\" * \___|\___/|_| \_\_____| + .\" * +-.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. ++.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + .\" * + .\" * This software is licensed as described in the file COPYING, which + .\" * you should have received as part of this distribution. The terms +@@ -36,13 +36,11 @@ address it already uses for the control connection. But it will use the port + number from the 227-response. + + This option thus allows libcurl to work around broken server installations +-that due to NATs, firewalls or incompetence report the wrong IP address +-back. Setting the option also reduces the risk for various sorts of client +-abuse by malicious servers. ++that due to NATs, firewalls or incompetence report the wrong IP address back. + + This option has no effect if PORT, EPRT or EPSV is used instead of PASV. + .SH DEFAULT +-1 since 7.74.0, was 0 before then. ++0 + .SH PROTOCOLS + FTP + .SH EXAMPLE +diff --git a/lib/conncache.c b/lib/conncache.c +index 42b0ed2..2804464 100644 +--- a/lib/conncache.c ++++ b/lib/conncache.c +@@ -158,12 +158,8 @@ static void hashkey(struct connectdata *conn, char *buf, + /* report back which name we used */ + *hostp = hostname; + +- /* put the numbers first so that the hostname gets cut off if too long */ +-#ifdef ENABLE_IPV6 +- msnprintf(buf, len, "%u/%ld/%s", conn->scope_id, port, hostname); +-#else +- msnprintf(buf, len, "%ld/%s", port, hostname); +-#endif ++ /* put the number first so that the hostname gets cut off if too long */ ++ msnprintf(buf, len, "%ld%s", port, hostname); + } + + void Curl_conncache_unlock(struct Curl_easy *data) +diff --git a/lib/connect.c b/lib/connect.c +index 050acb7..611d6d2 100644 +--- a/lib/connect.c ++++ b/lib/connect.c +@@ -624,7 +624,6 @@ void Curl_persistconninfo(struct connectdata *conn) + conn->data->info.conn_scheme = conn->handler->scheme; + conn->data->info.conn_protocol = conn->handler->protocol; + conn->data->info.conn_primary_port = conn->primary_port; +- conn->data->info.conn_remote_port = conn->remote_port; + conn->data->info.conn_local_port = conn->local_port; + } + +@@ -1337,15 +1336,15 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ + } + + struct connfind { +- long id_tofind; +- struct connectdata *found; ++ struct connectdata *tofind; ++ bool found; + }; + + static int conn_is_conn(struct connectdata *conn, void *param) + { + struct connfind *f = (struct connfind *)param; +- if(conn->connection_id == f->id_tofind) { +- f->found = conn; ++ if(conn == f->tofind) { ++ f->found = TRUE; + return 1; + } + return 0; +@@ -1367,22 +1366,21 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data, + * - that is associated with a multi handle, and whose connection + * was detached with CURLOPT_CONNECT_ONLY + */ +- if((data->state.lastconnect_id != -1) && (data->multi_easy || data->multi)) { +- struct connectdata *c; ++ if(data->state.lastconnect && (data->multi_easy || data->multi)) { ++ struct connectdata *c = data->state.lastconnect; + struct connfind find; +- find.id_tofind = data->state.lastconnect_id; +- find.found = NULL; ++ find.tofind = data->state.lastconnect; ++ find.found = FALSE; + + Curl_conncache_foreach(data, data->multi_easy? + &data->multi_easy->conn_cache: + &data->multi->conn_cache, &find, conn_is_conn); + + if(!find.found) { +- data->state.lastconnect_id = -1; ++ data->state.lastconnect = NULL; + return CURL_SOCKET_BAD; + } + +- c = find.found; + if(connp) { + /* only store this if the caller cares for it */ + *connp = c; +diff --git a/lib/content_encoding.c b/lib/content_encoding.c +index e646f31..6d47537 100644 +--- a/lib/content_encoding.c ++++ b/lib/content_encoding.c +@@ -934,9 +934,6 @@ static const content_encoding *find_encoding(const char *name, size_t len) + return NULL; + } + +-/* allow no more than 5 "chained" compression steps */ +-#define MAX_ENCODE_STACK 5 +- + /* Set-up the unencoding stack from the Content-Encoding header value. + * See RFC 7231 section 3.1.2.2. */ + CURLcode Curl_build_unencoding_stack(struct connectdata *conn, +@@ -944,7 +941,6 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn, + { + struct Curl_easy *data = conn->data; + struct SingleRequest *k = &data->req; +- int counter = 0; + + do { + const char *name; +@@ -979,11 +975,6 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn, + if(!encoding) + encoding = &error_encoding; /* Defer error at stack use. */ + +- if(++counter >= MAX_ENCODE_STACK) { +- failf(data, "Reject response due to %u content encodings", +- counter); +- return CURLE_BAD_CONTENT_ENCODING; +- } + /* Stack the unencoding stage. */ + writer = new_unencoding_writer(conn, encoding, k->writer_stack); + if(!writer) +diff --git a/lib/cookie.c b/lib/cookie.c +index 76b6206..0091132 100644 +--- a/lib/cookie.c ++++ b/lib/cookie.c +@@ -411,30 +411,6 @@ static bool bad_domain(const char *domain) + return !strchr(domain, '.') && !strcasecompare(domain, "localhost"); + } + +-/* +- RFC 6265 section 4.1.1 says a server should accept this range: +- +- cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E +- +- But Firefox and Chrome as of June 2022 accept space, comma and double-quotes +- fine. The prime reason for filtering out control bytes is that some HTTP +- servers return 400 for requests that contain such. +-*/ +-static int invalid_octets(const char *p) +-{ +- /* Reject all bytes \x01 - \x1f (*except* \x09, TAB) + \x7f */ +- static const char badoctets[] = { +- "\x01\x02\x03\x04\x05\x06\x07\x08\x0a" +- "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" +- "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f" +- }; +- size_t vlen, len; +- /* scan for all the octets that are *not* in cookie-octet */ +- len = strcspn(p, badoctets); +- vlen = strlen(p); +- return (len != vlen); +-} +- + /**************************************************************************** + * + * Curl_cookie_add() +@@ -581,11 +557,6 @@ Curl_cookie_add(struct Curl_easy *data, + badcookie = TRUE; + break; + } +- if(invalid_octets(whatptr) || invalid_octets(name)) { +- infof(data, "invalid octets in name/value, cookie dropped"); +- badcookie = TRUE; +- break; +- } + } + else if(!len) { + /* this was a "=" with no content, and we must allow +diff --git a/lib/easy.c b/lib/easy.c +index 3b4c778..6382cee 100644 +--- a/lib/easy.c ++++ b/lib/easy.c +@@ -832,7 +832,8 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data) + + /* the connection cache is setup on demand */ + outcurl->state.conn_cache = NULL; +- outcurl->state.lastconnect_id = -1; ++ ++ outcurl->state.lastconnect = NULL; + + outcurl->progress.flags = data->progress.flags; + outcurl->progress.callback = data->progress.callback; +diff --git a/lib/ftp.c b/lib/ftp.c +index 688c11e..469096f 100644 +--- a/lib/ftp.c ++++ b/lib/ftp.c +@@ -2497,7 +2497,7 @@ static CURLcode ftp_state_loggedin(struct connectdata *conn) + { + CURLcode result = CURLE_OK; + +- if(conn->bits.ftp_use_control_ssl) { ++ if(conn->ssl[FIRSTSOCKET].use) { + /* PBSZ = PROTECTION BUFFER SIZE. + + The 'draft-murray-auth-ftp-ssl' (draft 12, page 7) says: +@@ -2616,12 +2616,9 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + /* we have now received a full FTP server response */ + switch(ftpc->state) { + case FTP_WAIT220: +- if(ftpcode == 230) { +- /* 230 User logged in - already! Take as 220 if TLS required. */ +- if(data->set.use_ssl <= CURLUSESSL_TRY || +- conn->bits.ftp_use_control_ssl) +- return ftp_state_user_resp(conn, ftpcode, ftpc->state); +- } ++ if(ftpcode == 230) ++ /* 230 User logged in - already! */ ++ return ftp_state_user_resp(conn, ftpcode, ftpc->state); + else if(ftpcode != 220) { + failf(data, "Got a %03d ftp-server response when 220 was expected", + ftpcode); +@@ -2646,8 +2643,11 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + } + #endif + +- if(data->set.use_ssl && !conn->bits.ftp_use_control_ssl) { +- /* We don't have a SSL/TLS control connection yet, but FTPS is ++ if(data->set.use_ssl && ++ (!conn->ssl[FIRSTSOCKET].use || ++ (conn->bits.proxy_ssl_connected[FIRSTSOCKET] && ++ !conn->proxy_ssl[FIRSTSOCKET].use))) { ++ /* We don't have a SSL/TLS connection yet, but FTPS is + requested. Try a FTPS connection now */ + + ftpc->count3 = 0; +@@ -2680,9 +2680,6 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + case FTP_AUTH: + /* we have gotten the response to a previous AUTH command */ + +- if(pp->cache_size) +- return CURLE_WEIRD_SERVER_REPLY; /* Forbid pipelining in response. */ +- + /* RFC2228 (page 5) says: + * + * If the server is willing to accept the named security mechanism, +@@ -2695,7 +2692,6 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + result = Curl_ssl_connect(conn, FIRSTSOCKET); + if(!result) { + conn->bits.ftp_use_data_ssl = FALSE; /* clear-text data */ +- conn->bits.ftp_use_control_ssl = TRUE; /* SSL on control */ + result = ftp_state_user(conn); + } + } +@@ -3086,7 +3082,7 @@ static CURLcode ftp_block_statemach(struct connectdata *conn) + * + */ + static CURLcode ftp_connect(struct connectdata *conn, +- bool *done) /* see description above */ ++ bool *done) /* see description above */ + { + CURLcode result; + struct ftp_conn *ftpc = &conn->proto.ftpc; +@@ -3107,7 +3103,6 @@ static CURLcode ftp_connect(struct connectdata *conn, + result = Curl_ssl_connect(conn, FIRSTSOCKET); + if(result) + return result; +- conn->bits.ftp_use_control_ssl = TRUE; + } + + Curl_pp_init(pp); /* init the generic pingpong data */ +@@ -3778,131 +3773,129 @@ static CURLcode init_wc_data(struct connectdata *conn) + return result; + } + ++/* This is called recursively */ + static CURLcode wc_statemach(struct connectdata *conn) + { + struct WildcardData * const wildcard = &(conn->data->wildcard); + CURLcode result = CURLE_OK; + +- for(;;) { +- switch(wildcard->state) { +- case CURLWC_INIT: +- result = init_wc_data(conn); +- if(wildcard->state == CURLWC_CLEAN) +- /* only listing! */ +- return result; +- wildcard->state = result ? CURLWC_ERROR : CURLWC_MATCHING; +- return result; ++ switch(wildcard->state) { ++ case CURLWC_INIT: ++ result = init_wc_data(conn); ++ if(wildcard->state == CURLWC_CLEAN) ++ /* only listing! */ ++ break; ++ wildcard->state = result ? CURLWC_ERROR : CURLWC_MATCHING; ++ break; + +- case CURLWC_MATCHING: { +- /* In this state is LIST response successfully parsed, so lets restore +- previous WRITEFUNCTION callback and WRITEDATA pointer */ +- struct ftp_wc *ftpwc = wildcard->protdata; +- conn->data->set.fwrite_func = ftpwc->backup.write_function; +- conn->data->set.out = ftpwc->backup.file_descriptor; +- ftpwc->backup.write_function = ZERO_NULL; +- ftpwc->backup.file_descriptor = NULL; +- wildcard->state = CURLWC_DOWNLOADING; +- +- if(Curl_ftp_parselist_geterror(ftpwc->parser)) { +- /* error found in LIST parsing */ +- wildcard->state = CURLWC_CLEAN; +- continue; +- } +- if(wildcard->filelist.size == 0) { +- /* no corresponding file */ +- wildcard->state = CURLWC_CLEAN; +- return CURLE_REMOTE_FILE_NOT_FOUND; +- } +- continue; ++ case CURLWC_MATCHING: { ++ /* In this state is LIST response successfully parsed, so lets restore ++ previous WRITEFUNCTION callback and WRITEDATA pointer */ ++ struct ftp_wc *ftpwc = wildcard->protdata; ++ conn->data->set.fwrite_func = ftpwc->backup.write_function; ++ conn->data->set.out = ftpwc->backup.file_descriptor; ++ ftpwc->backup.write_function = ZERO_NULL; ++ ftpwc->backup.file_descriptor = NULL; ++ wildcard->state = CURLWC_DOWNLOADING; ++ ++ if(Curl_ftp_parselist_geterror(ftpwc->parser)) { ++ /* error found in LIST parsing */ ++ wildcard->state = CURLWC_CLEAN; ++ return wc_statemach(conn); + } ++ if(wildcard->filelist.size == 0) { ++ /* no corresponding file */ ++ wildcard->state = CURLWC_CLEAN; ++ return CURLE_REMOTE_FILE_NOT_FOUND; ++ } ++ return wc_statemach(conn); ++ } + +- case CURLWC_DOWNLOADING: { +- /* filelist has at least one file, lets get first one */ +- struct ftp_conn *ftpc = &conn->proto.ftpc; +- struct curl_fileinfo *finfo = wildcard->filelist.head->ptr; +- struct FTP *ftp = conn->data->req.protop; +- +- char *tmp_path = aprintf("%s%s", wildcard->path, finfo->filename); +- if(!tmp_path) +- return CURLE_OUT_OF_MEMORY; ++ case CURLWC_DOWNLOADING: { ++ /* filelist has at least one file, lets get first one */ ++ struct ftp_conn *ftpc = &conn->proto.ftpc; ++ struct curl_fileinfo *finfo = wildcard->filelist.head->ptr; ++ struct FTP *ftp = conn->data->req.protop; + +- /* switch default ftp->path and tmp_path */ +- free(ftp->pathalloc); +- ftp->pathalloc = ftp->path = tmp_path; +- +- infof(conn->data, "Wildcard - START of \"%s\"\n", finfo->filename); +- if(conn->data->set.chunk_bgn) { +- long userresponse; +- Curl_set_in_callback(conn->data, true); +- userresponse = conn->data->set.chunk_bgn( +- finfo, wildcard->customptr, (int)wildcard->filelist.size); +- Curl_set_in_callback(conn->data, false); +- switch(userresponse) { +- case CURL_CHUNK_BGN_FUNC_SKIP: +- infof(conn->data, "Wildcard - \"%s\" skipped by user\n", +- finfo->filename); +- wildcard->state = CURLWC_SKIP; +- continue; +- case CURL_CHUNK_BGN_FUNC_FAIL: +- return CURLE_CHUNK_FAILED; +- } +- } ++ char *tmp_path = aprintf("%s%s", wildcard->path, finfo->filename); ++ if(!tmp_path) ++ return CURLE_OUT_OF_MEMORY; + +- if(finfo->filetype != CURLFILETYPE_FILE) { ++ /* switch default ftp->path and tmp_path */ ++ free(ftp->pathalloc); ++ ftp->pathalloc = ftp->path = tmp_path; ++ ++ infof(conn->data, "Wildcard - START of \"%s\"\n", finfo->filename); ++ if(conn->data->set.chunk_bgn) { ++ long userresponse; ++ Curl_set_in_callback(conn->data, true); ++ userresponse = conn->data->set.chunk_bgn( ++ finfo, wildcard->customptr, (int)wildcard->filelist.size); ++ Curl_set_in_callback(conn->data, false); ++ switch(userresponse) { ++ case CURL_CHUNK_BGN_FUNC_SKIP: ++ infof(conn->data, "Wildcard - \"%s\" skipped by user\n", ++ finfo->filename); + wildcard->state = CURLWC_SKIP; +- continue; ++ return wc_statemach(conn); ++ case CURL_CHUNK_BGN_FUNC_FAIL: ++ return CURLE_CHUNK_FAILED; + } ++ } + +- if(finfo->flags & CURLFINFOFLAG_KNOWN_SIZE) +- ftpc->known_filesize = finfo->size; +- +- result = ftp_parse_url_path(conn); +- if(result) +- return result; ++ if(finfo->filetype != CURLFILETYPE_FILE) { ++ wildcard->state = CURLWC_SKIP; ++ return wc_statemach(conn); ++ } + +- /* we don't need the Curl_fileinfo of first file anymore */ +- Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); ++ if(finfo->flags & CURLFINFOFLAG_KNOWN_SIZE) ++ ftpc->known_filesize = finfo->size; + +- if(wildcard->filelist.size == 0) { /* remains only one file to down. */ +- wildcard->state = CURLWC_CLEAN; +- /* after that will be ftp_do called once again and no transfer +- will be done because of CURLWC_CLEAN state */ +- return CURLE_OK; +- } ++ result = ftp_parse_url_path(conn); ++ if(result) + return result; ++ ++ /* we don't need the Curl_fileinfo of first file anymore */ ++ Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); ++ ++ if(wildcard->filelist.size == 0) { /* remains only one file to down. */ ++ wildcard->state = CURLWC_CLEAN; ++ /* after that will be ftp_do called once again and no transfer ++ will be done because of CURLWC_CLEAN state */ ++ return CURLE_OK; + } ++ } break; + +- case CURLWC_SKIP: { +- if(conn->data->set.chunk_end) { +- Curl_set_in_callback(conn->data, true); +- conn->data->set.chunk_end(conn->data->wildcard.customptr); +- Curl_set_in_callback(conn->data, false); +- } +- Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); +- wildcard->state = (wildcard->filelist.size == 0) ? +- CURLWC_CLEAN : CURLWC_DOWNLOADING; +- continue; ++ case CURLWC_SKIP: { ++ if(conn->data->set.chunk_end) { ++ Curl_set_in_callback(conn->data, true); ++ conn->data->set.chunk_end(conn->data->wildcard.customptr); ++ Curl_set_in_callback(conn->data, false); + } ++ Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); ++ wildcard->state = (wildcard->filelist.size == 0) ? ++ CURLWC_CLEAN : CURLWC_DOWNLOADING; ++ return wc_statemach(conn); ++ } + +- case CURLWC_CLEAN: { +- struct ftp_wc *ftpwc = wildcard->protdata; +- result = CURLE_OK; +- if(ftpwc) +- result = Curl_ftp_parselist_geterror(ftpwc->parser); ++ case CURLWC_CLEAN: { ++ struct ftp_wc *ftpwc = wildcard->protdata; ++ result = CURLE_OK; ++ if(ftpwc) ++ result = Curl_ftp_parselist_geterror(ftpwc->parser); + +- wildcard->state = result ? CURLWC_ERROR : CURLWC_DONE; +- return result; +- } ++ wildcard->state = result ? CURLWC_ERROR : CURLWC_DONE; ++ } break; + +- case CURLWC_DONE: +- case CURLWC_ERROR: +- case CURLWC_CLEAR: +- if(wildcard->dtor) +- wildcard->dtor(wildcard->protdata); +- return result; +- } ++ case CURLWC_DONE: ++ case CURLWC_ERROR: ++ case CURLWC_CLEAR: ++ if(wildcard->dtor) ++ wildcard->dtor(wildcard->protdata); ++ break; + } +- /* UNREACHABLE */ ++ ++ return result; + } + + /*********************************************************************** +diff --git a/lib/http.c b/lib/http.c +index 4d6626b..837f53c 100644 +--- a/lib/http.c ++++ b/lib/http.c +@@ -733,21 +733,6 @@ output_auth_headers(struct connectdata *conn, + return CURLE_OK; + } + +-/* +- * allow_auth_to_host() tells if autentication, cookies or other "sensitive +- * data" can (still) be sent to this host. +- */ +-static bool allow_auth_to_host(struct Curl_easy *data) +-{ +- struct connectdata *conn = data->conn; +- return (!data->state.this_is_a_follow || +- data->set.allow_auth_to_other_hosts || +- (data->state.first_host && +- strcasecompare(data->state.first_host, conn->host.name) && +- (data->state.first_remote_port == conn->remote_port) && +- (data->state.first_remote_protocol == conn->handler->protocol))); +-} +- + /** + * Curl_http_output_auth() setups the authentication headers for the + * host/proxy and the correct authentication +@@ -816,12 +801,15 @@ Curl_http_output_auth(struct connectdata *conn, + with it */ + authproxy->done = TRUE; + +- /* To prevent the user+password to get sent to other than the original host +- due to a location-follow */ +- if(allow_auth_to_host(data) +- || conn->bits.netrc +- ) ++ /* To prevent the user+password to get sent to other than the original ++ host due to a location-follow, we do some weirdo checks here */ ++ if(!data->state.this_is_a_follow || ++ conn->bits.netrc || ++ !data->state.first_host || ++ data->set.allow_auth_to_other_hosts || ++ strcasecompare(data->state.first_host, conn->host.name)) { + result = output_auth_headers(conn, authhost, request, path, FALSE); ++ } + else + authhost->done = TRUE; + +@@ -1893,7 +1881,10 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn, + checkprefix("Cookie:", compare)) && + /* be careful of sending this potentially sensitive header to + other hosts */ +- !allow_auth_to_host(data)) ++ (data->state.this_is_a_follow && ++ data->state.first_host && ++ !data->set.allow_auth_to_other_hosts && ++ !strcasecompare(data->state.first_host, conn->host.name))) + ; + else { + result = Curl_add_bufferf(&req_buffer, "%s\r\n", compare); +@@ -2076,7 +2067,6 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) + return CURLE_OUT_OF_MEMORY; + + data->state.first_remote_port = conn->remote_port; +- data->state.first_remote_protocol = conn->handler->protocol; + } + + if((conn->handler->protocol&(PROTO_FAMILY_HTTP|CURLPROTO_FTP)) && +diff --git a/lib/imap.c b/lib/imap.c +index 0ca700f..66172bd 100644 +--- a/lib/imap.c ++++ b/lib/imap.c +@@ -917,18 +917,22 @@ static CURLcode imap_state_capability_resp(struct connectdata *conn, + line += wordlen; + } + } +- else if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { +- /* PREAUTH is not compatible with STARTTLS. */ +- if(imapcode == IMAP_RESP_OK && imapc->tls_supported && !imapc->preauth) { +- /* Switch to TLS connection now */ +- result = imap_perform_starttls(conn); ++ else if(imapcode == IMAP_RESP_OK) { ++ if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { ++ /* We don't have a SSL/TLS connection yet, but SSL is requested */ ++ if(imapc->tls_supported) ++ /* Switch to TLS connection now */ ++ result = imap_perform_starttls(conn); ++ else if(data->set.use_ssl == CURLUSESSL_TRY) ++ /* Fallback and carry on with authentication */ ++ result = imap_perform_authentication(conn); ++ else { ++ failf(data, "STARTTLS not supported."); ++ result = CURLE_USE_SSL_FAILED; ++ } + } +- else if(data->set.use_ssl <= CURLUSESSL_TRY) ++ else + result = imap_perform_authentication(conn); +- else { +- failf(data, "STARTTLS not available."); +- result = CURLE_USE_SSL_FAILED; +- } + } + else + result = imap_perform_authentication(conn); +@@ -946,10 +950,6 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + +- /* Pipelining in response is forbidden. */ +- if(data->conn->proto.imapc.pp.cache_size) +- return CURLE_WEIRD_SERVER_REPLY; +- + if(imapcode != IMAP_RESP_OK) { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied"); +diff --git a/lib/krb5.c b/lib/krb5.c +index 5b77e35..f50287a 100644 +--- a/lib/krb5.c ++++ b/lib/krb5.c +@@ -86,8 +86,11 @@ krb5_decode(void *app_data, void *buf, int len, + enc.value = buf; + enc.length = len; + maj = gss_unwrap(&min, *context, &enc, &dec, NULL, NULL); +- if(maj != GSS_S_COMPLETE) ++ if(maj != GSS_S_COMPLETE) { ++ if(len >= 4) ++ strcpy(buf, "599 "); + return -1; ++ } + + memcpy(buf, dec.value, dec.length); + len = curlx_uztosi(dec.length); +diff --git a/lib/multi.c b/lib/multi.c +index a1d25b6..6d819b4 100644 +--- a/lib/multi.c ++++ b/lib/multi.c +@@ -451,7 +451,6 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi, + data->state.conn_cache = &data->share->conn_cache; + else + data->state.conn_cache = &multi->conn_cache; +- data->state.lastconnect_id = -1; + + #ifdef USE_LIBPSL + /* Do the same for PSL. */ +@@ -664,11 +663,11 @@ static CURLcode multi_done(struct Curl_easy *data, + CONN_UNLOCK(data); + if(Curl_conncache_return_conn(data, conn)) { + /* remember the most recently used connection */ +- data->state.lastconnect_id = conn->connection_id; ++ data->state.lastconnect = conn; + infof(data, "%s\n", buffer); + } + else +- data->state.lastconnect_id = -1; ++ data->state.lastconnect = NULL; + } + + Curl_free_request_state(data); +diff --git a/lib/pop3.c b/lib/pop3.c +index 8a2d52e..57c1373 100644 +--- a/lib/pop3.c ++++ b/lib/pop3.c +@@ -721,23 +721,28 @@ static CURLcode pop3_state_capa_resp(struct connectdata *conn, int pop3code, + } + } + } ++ else if(pop3code == '+') { ++ if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { ++ /* We don't have a SSL/TLS connection yet, but SSL is requested */ ++ if(pop3c->tls_supported) ++ /* Switch to TLS connection now */ ++ result = pop3_perform_starttls(conn); ++ else if(data->set.use_ssl == CURLUSESSL_TRY) ++ /* Fallback and carry on with authentication */ ++ result = pop3_perform_authentication(conn); ++ else { ++ failf(data, "STLS not supported."); ++ result = CURLE_USE_SSL_FAILED; ++ } ++ } ++ else ++ result = pop3_perform_authentication(conn); ++ } + else { + /* Clear text is supported when CAPA isn't recognised */ +- if(pop3code != '+') +- pop3c->authtypes |= POP3_TYPE_CLEARTEXT; ++ pop3c->authtypes |= POP3_TYPE_CLEARTEXT; + +- if(!data->set.use_ssl || conn->ssl[FIRSTSOCKET].use) +- result = pop3_perform_authentication(conn); +- else if(pop3code == '+' && pop3c->tls_supported) +- /* Switch to TLS connection now */ +- result = pop3_perform_starttls(conn); +- else if(data->set.use_ssl <= CURLUSESSL_TRY) +- /* Fallback and carry on with authentication */ +- result = pop3_perform_authentication(conn); +- else { +- failf(data, "STLS not supported."); +- result = CURLE_USE_SSL_FAILED; +- } ++ result = pop3_perform_authentication(conn); + } + + return result; +@@ -753,10 +758,6 @@ static CURLcode pop3_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + +- /* Pipelining in response is forbidden. */ +- if(data->conn->proto.pop3c.pp.cache_size) +- return CURLE_WEIRD_SERVER_REPLY; +- + if(pop3code != '+') { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied"); +diff --git a/lib/setopt.c b/lib/setopt.c +index 60bdb27..5f88ad3 100644 +--- a/lib/setopt.c ++++ b/lib/setopt.c +@@ -486,7 +486,6 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + } + else + data->set.httpreq = HTTPREQ_GET; +- data->set.upload = FALSE; + break; + + case CURLOPT_COPYPOSTFIELDS: +@@ -2131,7 +2130,6 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + + case CURLOPT_SSL_OPTIONS: + arg = va_arg(param, long); +- data->set.ssl.primary.ssl_options = (unsigned char)(arg & 0xff); + data->set.ssl.enable_beast = + (bool)((arg&CURLSSLOPT_ALLOW_BEAST) ? TRUE : FALSE); + data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE); +@@ -2141,7 +2139,6 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + #ifndef CURL_DISABLE_PROXY + case CURLOPT_PROXY_SSL_OPTIONS: + arg = va_arg(param, long); +- data->set.proxy_ssl.primary.ssl_options = (unsigned char)(arg & 0xff); + data->set.proxy_ssl.enable_beast = + (bool)((arg&CURLSSLOPT_ALLOW_BEAST) ? TRUE : FALSE); + data->set.proxy_ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE); +@@ -2540,47 +2537,44 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + case CURLOPT_TLSAUTH_USERNAME: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_ORIG], + va_arg(param, char *)); +- if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && +- !data->set.ssl.primary.authtype) +- data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype) ++ data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ + break; + case CURLOPT_PROXY_TLSAUTH_USERNAME: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_PROXY], + va_arg(param, char *)); + if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] && +- !data->set.proxy_ssl.primary.authtype) +- data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default to +- SRP */ ++ !data->set.proxy_ssl.authtype) ++ data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ + break; + case CURLOPT_TLSAUTH_PASSWORD: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_ORIG], + va_arg(param, char *)); +- if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && +- !data->set.ssl.primary.authtype) +- data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default */ ++ if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype) ++ data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ + break; + case CURLOPT_PROXY_TLSAUTH_PASSWORD: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_PROXY], + va_arg(param, char *)); + if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] && +- !data->set.proxy_ssl.primary.authtype) +- data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default */ ++ !data->set.proxy_ssl.authtype) ++ data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ + break; + case CURLOPT_TLSAUTH_TYPE: + argptr = va_arg(param, char *); + if(!argptr || + strncasecompare(argptr, "SRP", strlen("SRP"))) +- data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; ++ data->set.ssl.authtype = CURL_TLSAUTH_SRP; + else +- data->set.ssl.primary.authtype = CURL_TLSAUTH_NONE; ++ data->set.ssl.authtype = CURL_TLSAUTH_NONE; + break; + case CURLOPT_PROXY_TLSAUTH_TYPE: + argptr = va_arg(param, char *); + if(!argptr || + strncasecompare(argptr, "SRP", strlen("SRP"))) +- data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; ++ data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; + else +- data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_NONE; ++ data->set.proxy_ssl.authtype = CURL_TLSAUTH_NONE; + break; + #endif + #ifdef USE_ARES +diff --git a/lib/smtp.c b/lib/smtp.c +index 718b289..65220b0 100644 +--- a/lib/smtp.c ++++ b/lib/smtp.c +@@ -680,10 +680,6 @@ static CURLcode smtp_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + +- /* Pipelining in response is forbidden. */ +- if(data->conn->proto.smtpc.pp.cache_size) +- return CURLE_WEIRD_SERVER_REPLY; +- + if(smtpcode != 220) { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied, code %d", smtpcode); +diff --git a/lib/strcase.c b/lib/strcase.c +index 68e2773..a894712 100644 +--- a/lib/strcase.c ++++ b/lib/strcase.c +@@ -249,16 +249,6 @@ void Curl_strntolower(char *dest, const char *src, size_t n) + } while(*src++ && --n); + } + +-/* Compare case-sensitive NUL-terminated strings, taking care of possible +- * null pointers. Return true if arguments match. +- */ +-bool Curl_safecmp(char *a, char *b) +-{ +- if(a && b) +- return !strcmp(a, b); +- return !a && !b; +-} +- + /* --- public functions --- */ + + int curl_strequal(const char *first, const char *second) +diff --git a/lib/strcase.h b/lib/strcase.h +index 3665d5a..baa768b 100644 +--- a/lib/strcase.h ++++ b/lib/strcase.h +@@ -49,6 +49,4 @@ char Curl_raw_tolower(char in); + void Curl_strntoupper(char *dest, const char *src, size_t n); + void Curl_strntolower(char *dest, const char *src, size_t n); + +-bool Curl_safecmp(char *a, char *b); +- + #endif /* HEADER_CURL_STRCASE_H */ +diff --git a/lib/telnet.c b/lib/telnet.c +index 3347ad6..4bf4c65 100644 +--- a/lib/telnet.c ++++ b/lib/telnet.c +@@ -967,17 +967,12 @@ static void suboption(struct connectdata *conn) + size_t tmplen = (strlen(v->data) + 1); + /* Add the variable only if it fits */ + if(len + tmplen < (int)sizeof(temp)-6) { +- int rv; +- char sep[2] = ""; +- varval[0] = 0; +- rv = sscanf(v->data, "%127[^,]%1[,]%127s", varname, sep, varval); +- if(rv == 1) +- len += msnprintf((char *)&temp[len], sizeof(temp) - len, +- "%c%s", CURL_NEW_ENV_VAR, varname); +- else if(rv >= 2) +- len += msnprintf((char *)&temp[len], sizeof(temp) - len, +- "%c%s%c%s", CURL_NEW_ENV_VAR, varname, +- CURL_NEW_ENV_VALUE, varval); ++ if(sscanf(v->data, "%127[^,],%127s", varname, varval)) { ++ msnprintf((char *)&temp[len], sizeof(temp) - len, ++ "%c%s%c%s", CURL_NEW_ENV_VAR, varname, ++ CURL_NEW_ENV_VALUE, varval); ++ len += tmplen; ++ } + } + } + msnprintf((char *)&temp[len], sizeof(temp) - len, +diff --git a/lib/transfer.c b/lib/transfer.c +index f279c5b..ead8b36 100644 +--- a/lib/transfer.c ++++ b/lib/transfer.c +@@ -1572,9 +1572,6 @@ CURLcode Curl_follow(struct Curl_easy *data, + data->set.followlocation++; /* count location-followers */ + + if(data->set.http_auto_referer) { +- CURLU *u; +- char *referer; +- + /* We are asked to automatically set the previous URL as the referer + when we get the next URL. We pick the ->url field, which may or may + not be 100% correct */ +@@ -1584,27 +1581,9 @@ CURLcode Curl_follow(struct Curl_easy *data, + data->change.referer_alloc = FALSE; + } + +- /* Make a copy of the URL without crenditals and fragment */ +- u = curl_url(); +- if(!u) +- return CURLE_OUT_OF_MEMORY; +- +- uc = curl_url_set(u, CURLUPART_URL, data->change.url, 0); +- if(!uc) +- uc = curl_url_set(u, CURLUPART_FRAGMENT, NULL, 0); +- if(!uc) +- uc = curl_url_set(u, CURLUPART_USER, NULL, 0); +- if(!uc) +- uc = curl_url_set(u, CURLUPART_PASSWORD, NULL, 0); +- if(!uc) +- uc = curl_url_get(u, CURLUPART_URL, &referer, 0); +- +- curl_url_cleanup(u); +- +- if(uc || referer == NULL) ++ data->change.referer = strdup(data->change.url); ++ if(!data->change.referer) + return CURLE_OUT_OF_MEMORY; +- +- data->change.referer = referer; + data->change.referer_alloc = TRUE; /* yes, free this later */ + } + } +@@ -1629,53 +1608,10 @@ CURLcode Curl_follow(struct Curl_easy *data, + return CURLE_OUT_OF_MEMORY; + } + else { ++ + uc = curl_url_get(data->state.uh, CURLUPART_URL, &newurl, 0); + if(uc) + return Curl_uc_to_curlcode(uc); +- +- /* Clear auth if this redirects to a different port number or protocol, +- unless permitted */ +- if(!data->set.allow_auth_to_other_hosts && (type != FOLLOW_FAKE)) { +- char *portnum; +- int port; +- bool clear = FALSE; +- +- uc = curl_url_get(data->state.uh, CURLUPART_PORT, &portnum, +- CURLU_DEFAULT_PORT); +- if(uc) { +- free(newurl); +- return Curl_uc_to_curlcode(uc); +- } +- port = atoi(portnum); +- free(portnum); +- +- if(port != data->info.conn_remote_port) { +- infof(data, "Clear auth, redirects to port from %u to %u", +- data->info.conn_remote_port, port); +- clear = TRUE; +- } +- else { +- char *scheme; +- const struct Curl_handler *p; +- uc = curl_url_get(data->state.uh, CURLUPART_SCHEME, &scheme, 0); +- if(uc) { +- free(newurl); +- return Curl_uc_to_curlcode(uc); +- } +- +- p = Curl_builtin_scheme(scheme); +- if(p && (p->protocol != data->info.conn_protocol)) { +- infof(data, "Clear auth, redirects scheme from %s to %s", +- data->info.conn_scheme, scheme); +- clear = TRUE; +- } +- free(scheme); +- } +- if(clear) { +- Curl_safefree(data->set.str[STRING_USERNAME]); +- Curl_safefree(data->set.str[STRING_PASSWORD]); +- } +- } + } + + if(type == FOLLOW_FAKE) { +diff --git a/lib/url.c b/lib/url.c +index 01f7eda..56fb736 100644 +--- a/lib/url.c ++++ b/lib/url.c +@@ -456,7 +456,6 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) + set->ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */ + set->ftp_use_pret = FALSE; /* mainly useful for drftpd servers */ + set->ftp_filemethod = FTPFILE_MULTICWD; +- set->ftp_skip_ip = TRUE; /* skip PASV IP by default */ + #endif + set->dns_cache_timeout = 60; /* Timeout every 60 seconds by default */ + +@@ -483,7 +482,7 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) + set->ssl.primary.verifypeer = TRUE; + set->ssl.primary.verifyhost = TRUE; + #ifdef USE_TLS_SRP +- set->ssl.primary.authtype = CURL_TLSAUTH_NONE; ++ set->ssl.authtype = CURL_TLSAUTH_NONE; + #endif + set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth + type */ +@@ -619,7 +618,7 @@ CURLcode Curl_open(struct Curl_easy **curl) + Curl_initinfo(data); + + /* most recent connection is not yet defined */ +- data->state.lastconnect_id = -1; ++ data->state.lastconnect = NULL; + + data->progress.flags |= PGRS_HIDE; + data->state.current_speed = -1; /* init to negative == impossible */ +@@ -997,12 +996,6 @@ static void prune_dead_connections(struct Curl_easy *data) + } + } + +-static bool ssh_config_matches(struct connectdata *one, +- struct connectdata *two) +-{ +- return (Curl_safecmp(one->proto.sshc.rsa, two->proto.sshc.rsa) && +- Curl_safecmp(one->proto.sshc.rsa_pub, two->proto.sshc.rsa_pub)); +-} + /* + * Given one filled in connection struct (named needle), this function should + * detect if there already is one that has all the significant details +@@ -1225,19 +1218,12 @@ ConnectionExists(struct Curl_easy *data, + /* This protocol requires credentials per connection, + so verify that we're using the same name and password as well */ + if(strcmp(needle->user, check->user) || +- strcmp(needle->passwd, check->passwd) || +- !Curl_safecmp(needle->sasl_authzid, check->sasl_authzid) || +- !Curl_safecmp(needle->oauth_bearer, check->oauth_bearer)) { ++ strcmp(needle->passwd, check->passwd)) { + /* one of them was different */ + continue; + } + } + +- if(get_protocol_family(needle->handler->protocol) == PROTO_FAMILY_SSH) { +- if(!ssh_config_matches(needle, check)) +- continue; +- } +- + if(!needle->bits.httpproxy || (needle->handler->flags&PROTOPT_SSL) || + needle->bits.tunnel_proxy) { + /* The requested connection does not use a HTTP proxy or it uses SSL or +@@ -1619,16 +1605,10 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) + conn->ssl_config.verifystatus = data->set.ssl.primary.verifystatus; + conn->ssl_config.verifypeer = data->set.ssl.primary.verifypeer; + conn->ssl_config.verifyhost = data->set.ssl.primary.verifyhost; +- conn->ssl_config.ssl_options = data->set.ssl.primary.ssl_options; +-#ifdef USE_TLS_SRP +-#endif + conn->proxy_ssl_config.verifystatus = + data->set.proxy_ssl.primary.verifystatus; + conn->proxy_ssl_config.verifypeer = data->set.proxy_ssl.primary.verifypeer; + conn->proxy_ssl_config.verifyhost = data->set.proxy_ssl.primary.verifyhost; +- conn->proxy_ssl_config.ssl_options = data->set.proxy_ssl.primary.ssl_options; +-#ifdef USE_TLS_SRP +-#endif + conn->ip_version = data->set.ipver; + conn->bits.connect_only = data->set.connect_only; + conn->transport = TRNSPRT_TCP; /* most of them are TCP streams */ +@@ -2753,14 +2733,12 @@ static CURLcode override_login(struct Curl_easy *data, + + /* for updated strings, we update them in the URL */ + if(user_changed) { +- uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp, +- CURLU_URLENCODE); ++ uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp, 0); + if(uc) + return Curl_uc_to_curlcode(uc); + } + if(passwd_changed) { +- uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp, +- CURLU_URLENCODE); ++ uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp, 0); + if(uc) + return Curl_uc_to_curlcode(uc); + } +@@ -3374,14 +3352,6 @@ static CURLcode create_conn(struct Curl_easy *data, + } + } + +- if(data->set.str[STRING_BEARER]) { +- conn->oauth_bearer = strdup(data->set.str[STRING_BEARER]); +- if(!conn->oauth_bearer) { +- result = CURLE_OUT_OF_MEMORY; +- goto out; +- } +- } +- + #ifdef USE_UNIX_SOCKETS + if(data->set.str[STRING_UNIX_SOCKET_PATH]) { + conn->unix_domain_socket = strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); +@@ -3550,9 +3520,6 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.proxy_ssl.primary.CApath = data->set.str[STRING_SSL_CAPATH_PROXY]; + data->set.ssl.primary.CAfile = data->set.str[STRING_SSL_CAFILE_ORIG]; + data->set.proxy_ssl.primary.CAfile = data->set.str[STRING_SSL_CAFILE_PROXY]; +- data->set.ssl.primary.issuercert = data->set.str[STRING_SSL_ISSUERCERT_ORIG]; +- data->set.proxy_ssl.primary.issuercert = +- data->set.str[STRING_SSL_ISSUERCERT_PROXY]; + data->set.ssl.primary.random_file = data->set.str[STRING_SSL_RANDOM_FILE]; + data->set.proxy_ssl.primary.random_file = + data->set.str[STRING_SSL_RANDOM_FILE]; +@@ -3571,9 +3538,10 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.proxy_ssl.primary.pinned_key = + data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY]; + +- data->set.ssl.primary.CRLfile = data->set.str[STRING_SSL_CRLFILE_ORIG]; +- data->set.proxy_ssl.primary.CRLfile = +- data->set.str[STRING_SSL_CRLFILE_PROXY]; ++ data->set.ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_ORIG]; ++ data->set.proxy_ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_PROXY]; ++ data->set.ssl.issuercert = data->set.str[STRING_SSL_ISSUERCERT_ORIG]; ++ data->set.proxy_ssl.issuercert = data->set.str[STRING_SSL_ISSUERCERT_PROXY]; + data->set.ssl.cert = data->set.str[STRING_CERT_ORIG]; + data->set.proxy_ssl.cert = data->set.str[STRING_CERT_PROXY]; + data->set.ssl.cert_type = data->set.str[STRING_CERT_TYPE_ORIG]; +@@ -3587,12 +3555,10 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.ssl.primary.clientcert = data->set.str[STRING_CERT_ORIG]; + data->set.proxy_ssl.primary.clientcert = data->set.str[STRING_CERT_PROXY]; + #ifdef USE_TLS_SRP +- data->set.ssl.primary.username = data->set.str[STRING_TLSAUTH_USERNAME_ORIG]; +- data->set.proxy_ssl.primary.username = +- data->set.str[STRING_TLSAUTH_USERNAME_PROXY]; +- data->set.ssl.primary.password = data->set.str[STRING_TLSAUTH_PASSWORD_ORIG]; +- data->set.proxy_ssl.primary.password = +- data->set.str[STRING_TLSAUTH_PASSWORD_PROXY]; ++ data->set.ssl.username = data->set.str[STRING_TLSAUTH_USERNAME_ORIG]; ++ data->set.proxy_ssl.username = data->set.str[STRING_TLSAUTH_USERNAME_PROXY]; ++ data->set.ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD_ORIG]; ++ data->set.proxy_ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD_PROXY]; + #endif + + if(!Curl_clone_primary_ssl_config(&data->set.ssl.primary, +diff --git a/lib/urldata.h b/lib/urldata.h +index 8f3c31d..3effb16 100644 +--- a/lib/urldata.h ++++ b/lib/urldata.h +@@ -224,20 +224,12 @@ struct ssl_primary_config { + long version_max; /* max supported version the client wants to use*/ + char *CApath; /* certificate dir (doesn't work on windows) */ + char *CAfile; /* certificate to verify peer against */ +- char *issuercert; /* optional issuer certificate filename */ + char *clientcert; + char *random_file; /* path to file containing "random" data */ + char *egdsocket; /* path to file containing the EGD daemon socket */ + char *cipher_list; /* list of ciphers to use */ + char *cipher_list13; /* list of TLS 1.3 cipher suites to use */ + char *pinned_key; +- char *CRLfile; /* CRL to check certificate revocation */ +-#ifdef USE_TLS_SRP +- char *username; /* TLS username (for, e.g., SRP) */ +- char *password; /* TLS password (for, e.g., SRP) */ +- enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */ +-#endif +- unsigned char ssl_options; /* the CURLOPT_SSL_OPTIONS bitmask */ + BIT(verifypeer); /* set TRUE if this is desired */ + BIT(verifyhost); /* set TRUE if CN/SAN must match hostname */ + BIT(verifystatus); /* set TRUE if certificate status must be checked */ +@@ -247,6 +239,8 @@ struct ssl_primary_config { + struct ssl_config_data { + struct ssl_primary_config primary; + long certverifyresult; /* result from the certificate verification */ ++ char *CRLfile; /* CRL to check certificate revocation */ ++ char *issuercert;/* optional issuer certificate filename */ + curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */ + void *fsslctxp; /* parameter for call back */ + char *cert; /* client certificate file name */ +@@ -254,6 +248,11 @@ struct ssl_config_data { + char *key; /* private key file name */ + char *key_type; /* format for private key (default: PEM) */ + char *key_passwd; /* plain text private key password */ ++#ifdef USE_TLS_SRP ++ char *username; /* TLS username (for, e.g., SRP) */ ++ char *password; /* TLS password (for, e.g., SRP) */ ++ enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */ ++#endif + BIT(certinfo); /* gather lots of certificate info */ + BIT(falsestart); + BIT(enable_beast); /* allow this flaw for interoperability's sake*/ +@@ -454,7 +453,6 @@ struct ConnectBits { + EPRT doesn't work we disable it for the forthcoming + requests */ + BIT(ftp_use_data_ssl); /* Enabled SSL for the data connection */ +- BIT(ftp_use_control_ssl); /* Enabled SSL for the control connection */ + #endif + BIT(netrc); /* name+password provided by netrc */ + BIT(userpwd_in_url); /* name+password found in url */ +@@ -1116,11 +1114,7 @@ struct PureInfo { + reused, in the connection cache. */ + + char conn_primary_ip[MAX_IPADR_LEN]; +- int conn_primary_port; /* this is the destination port to the connection, +- which might have been a proxy */ +- int conn_remote_port; /* this is the "remote port", which is the port +- number of the used URL, independent of proxy or +- not */ ++ long conn_primary_port; + char conn_local_ip[MAX_IPADR_LEN]; + long conn_local_port; + const char *conn_scheme; +@@ -1307,7 +1301,7 @@ struct UrlState { + /* buffers to store authentication data in, as parsed from input options */ + struct curltime keeps_speed; /* for the progress meter really */ + +- long lastconnect_id; /* The last connection, -1 if undefined */ ++ struct connectdata *lastconnect; /* The last connection, NULL if undefined */ + + char *headerbuff; /* allocated buffer to store headers in */ + size_t headersize; /* size of the allocation */ +@@ -1316,15 +1310,13 @@ struct UrlState { + char *ulbuf; /* allocated upload buffer or NULL */ + curl_off_t current_speed; /* the ProgressShow() function sets this, + bytes / second */ +- +- /* host name, port number and protocol of the first (not followed) request. +- if set, this should be the host name that we will sent authorization to, +- no else. Used to make Location: following not keep sending user+password. +- This is strdup()ed data. */ +- char *first_host; +- int first_remote_port; +- unsigned int first_remote_protocol; +- ++ char *first_host; /* host name of the first (not followed) request. ++ if set, this should be the host name that we will ++ sent authorization to, no else. Used to make Location: ++ following not keep sending user+password... This is ++ strdup() data. ++ */ ++ int first_remote_port; /* remote port of the first (not followed) request */ + struct curl_ssl_session *session; /* array of 'max_ssl_sessions' size */ + long sessionage; /* number of the most recent session */ + unsigned int tempcount; /* number of entries in use in tempwrite, 0 - 3 */ +diff --git a/lib/vssh/ssh.h b/lib/vssh/ssh.h +index e9e5a34..3213c5a 100644 +--- a/lib/vssh/ssh.h ++++ b/lib/vssh/ssh.h +@@ -117,8 +117,8 @@ struct ssh_conn { + + /* common */ + const char *passphrase; /* pass-phrase to use */ +- char *rsa_pub; /* strdup'ed public key file */ +- char *rsa; /* strdup'ed private key file */ ++ char *rsa_pub; /* path name */ ++ char *rsa; /* path name */ + bool authed; /* the connection has been authenticated fine */ + sshstate state; /* always use ssh.c:state() to change state! */ + sshstate nextstate; /* the state to goto after stopping */ +diff --git a/lib/vtls/bearssl.c b/lib/vtls/bearssl.c +index 32cb0a4..67f9458 100644 +--- a/lib/vtls/bearssl.c ++++ b/lib/vtls/bearssl.c +@@ -372,8 +372,7 @@ static CURLcode bearssl_connect_step1(struct connectdata *conn, int sockindex) + void *session; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- &session, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, &session, NULL, sockindex)) { + br_ssl_engine_set_session_parameters(&BACKEND->ctx.eng, session); + infof(data, "BearSSL: re-using session ID\n"); + } +@@ -561,12 +560,10 @@ static CURLcode bearssl_connect_step3(struct connectdata *conn, int sockindex) + return CURLE_OUT_OF_MEMORY; + br_ssl_engine_get_session_parameters(&BACKEND->ctx.eng, session); + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- &oldsession, NULL, sockindex)); ++ incache = !(Curl_ssl_getsessionid(conn, &oldsession, NULL, sockindex)); + if(incache) + Curl_ssl_delsessionid(conn, oldsession); +- ret = Curl_ssl_addsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- session, 0, sockindex); ++ ret = Curl_ssl_addsessionid(conn, session, 0, sockindex); + Curl_ssl_sessionid_unlock(conn); + if(ret) { + free(session); +diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c +index 92dbcd5..571e83b 100644 +--- a/lib/vtls/gtls.c ++++ b/lib/vtls/gtls.c +@@ -581,9 +581,8 @@ gtls_connect_step1(struct connectdata *conn, + } + + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { +- infof(data, "Using TLS-SRP username: %s\n", +- SSL_SET_OPTION(primary.username)); ++ if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { ++ infof(data, "Using TLS-SRP username: %s\n", SSL_SET_OPTION(username)); + + rc = gnutls_srp_allocate_client_credentials( + &BACKEND->srp_client_cred); +@@ -594,8 +593,8 @@ gtls_connect_step1(struct connectdata *conn, + } + + rc = gnutls_srp_set_client_credentials(BACKEND->srp_client_cred, +- SSL_SET_OPTION(primary.username), +- SSL_SET_OPTION(primary.password)); ++ SSL_SET_OPTION(username), ++ SSL_SET_OPTION(password)); + if(rc != GNUTLS_E_SUCCESS) { + failf(data, "gnutls_srp_set_client_cred() failed: %s", + gnutls_strerror(rc)); +@@ -649,19 +648,19 @@ gtls_connect_step1(struct connectdata *conn, + } + #endif + +- if(SSL_SET_OPTION(primary.CRLfile)) { ++ if(SSL_SET_OPTION(CRLfile)) { + /* set the CRL list file */ + rc = gnutls_certificate_set_x509_crl_file(BACKEND->cred, +- SSL_SET_OPTION(primary.CRLfile), ++ SSL_SET_OPTION(CRLfile), + GNUTLS_X509_FMT_PEM); + if(rc < 0) { + failf(data, "error reading crl file %s (%s)", +- SSL_SET_OPTION(primary.CRLfile), gnutls_strerror(rc)); ++ SSL_SET_OPTION(CRLfile), gnutls_strerror(rc)); + return CURLE_SSL_CRL_BADFILE; + } + else + infof(data, "found %d CRL in %s\n", +- rc, SSL_SET_OPTION(primary.CRLfile)); ++ rc, SSL_SET_OPTION(CRLfile)); + } + + /* Initialize TLS session as a client */ +@@ -788,7 +787,7 @@ gtls_connect_step1(struct connectdata *conn, + #ifdef USE_TLS_SRP + /* Only add SRP to the cipher list if SRP is requested. Otherwise + * GnuTLS will disable TLS 1.3 support. */ +- if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { ++ if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { + size_t len = strlen(prioritylist); + + char *prioritysrp = malloc(len + sizeof(GNUTLS_SRP) + 1); +@@ -885,7 +884,7 @@ gtls_connect_step1(struct connectdata *conn, + + #ifdef USE_TLS_SRP + /* put the credentials to the current session */ +- if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { ++ if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { + rc = gnutls_credentials_set(session, GNUTLS_CRD_SRP, + BACKEND->srp_client_cred); + if(rc != GNUTLS_E_SUCCESS) { +@@ -943,8 +942,7 @@ gtls_connect_step1(struct connectdata *conn, + size_t ssl_idsize; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- &ssl_sessionid, &ssl_idsize, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, &ssl_idsize, sockindex)) { + /* we got a session id, use it! */ + gnutls_session_set_data(session, ssl_sessionid, ssl_idsize); + +@@ -1065,10 +1063,10 @@ gtls_connect_step3(struct connectdata *conn, + if(!chainp) { + if(SSL_CONN_CONFIG(verifypeer) || + SSL_CONN_CONFIG(verifyhost) || +- SSL_CONN_CONFIG(issuercert)) { ++ SSL_SET_OPTION(issuercert)) { + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP +- && SSL_SET_OPTION(primary.username) != NULL ++ if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP ++ && SSL_SET_OPTION(username) != NULL + && !SSL_CONN_CONFIG(verifypeer) + && gnutls_cipher_get(session)) { + /* no peer cert, but auth is ok if we have SRP user and cipher and no +@@ -1122,8 +1120,7 @@ gtls_connect_step3(struct connectdata *conn, + failf(data, "server certificate verification failed. CAfile: %s " + "CRLfile: %s", SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile): + "none", +- SSL_SET_OPTION(primary.CRLfile) ? +- SSL_SET_OPTION(primary.CRLfile) : "none"); ++ SSL_SET_OPTION(CRLfile)?SSL_SET_OPTION(CRLfile):"none"); + return CURLE_PEER_FAILED_VERIFICATION; + } + else +@@ -1248,21 +1245,21 @@ gtls_connect_step3(struct connectdata *conn, + gnutls_x509_crt_t format */ + gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER); + +- if(SSL_CONN_CONFIG(issuercert)) { ++ if(SSL_SET_OPTION(issuercert)) { + gnutls_x509_crt_init(&x509_issuer); +- issuerp = load_file(SSL_CONN_CONFIG(issuercert)); ++ issuerp = load_file(SSL_SET_OPTION(issuercert)); + gnutls_x509_crt_import(x509_issuer, &issuerp, GNUTLS_X509_FMT_PEM); + rc = gnutls_x509_crt_check_issuer(x509_cert, x509_issuer); + gnutls_x509_crt_deinit(x509_issuer); + unload_file(issuerp); + if(rc <= 0) { + failf(data, "server certificate issuer check failed (IssuerCert: %s)", +- SSL_CONN_CONFIG(issuercert)?SSL_CONN_CONFIG(issuercert):"none"); ++ SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none"); + gnutls_x509_crt_deinit(x509_cert); + return CURLE_SSL_ISSUER_ERROR; + } + infof(data, "\t server certificate issuer check OK (Issuer Cert: %s)\n", +- SSL_CONN_CONFIG(issuercert)?SSL_CONN_CONFIG(issuercert):"none"); ++ SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none"); + } + + size = sizeof(certbuf); +@@ -1493,8 +1490,7 @@ gtls_connect_step3(struct connectdata *conn, + gnutls_session_get_data(session, connect_sessionid, &connect_idsize); + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- &ssl_sessionid, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, + sockindex)); + if(incache) { + /* there was one before in the cache, so instead of risking that the +@@ -1503,8 +1499,7 @@ gtls_connect_step3(struct connectdata *conn, + } + + /* store this session id */ +- result = Curl_ssl_addsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- connect_sessionid, connect_idsize, ++ result = Curl_ssl_addsessionid(conn, connect_sessionid, connect_idsize, + sockindex); + Curl_ssl_sessionid_unlock(conn); + if(result) { +@@ -1710,8 +1705,8 @@ static int Curl_gtls_shutdown(struct connectdata *conn, int sockindex) + gnutls_certificate_free_credentials(BACKEND->cred); + + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP +- && SSL_SET_OPTION(primary.username) != NULL) ++ if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP ++ && SSL_SET_OPTION(username) != NULL) + gnutls_srp_free_client_credentials(BACKEND->srp_client_cred); + #endif + +diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c +index 783ecd9..e34ec9d 100644 +--- a/lib/vtls/mbedtls.c ++++ b/lib/vtls/mbedtls.c +@@ -453,8 +453,7 @@ mbed_connect_step1(struct connectdata *conn, + void *old_session = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- &old_session, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, &old_session, NULL, sockindex)) { + ret = mbedtls_ssl_set_session(&BACKEND->ssl, old_session); + if(ret) { + Curl_ssl_sessionid_unlock(conn); +@@ -710,7 +709,6 @@ mbed_connect_step3(struct connectdata *conn, + int ret; + mbedtls_ssl_session *our_ssl_sessionid; + void *old_ssl_sessionid = NULL; +- bool isproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + our_ssl_sessionid = malloc(sizeof(mbedtls_ssl_session)); + if(!our_ssl_sessionid) +@@ -729,10 +727,10 @@ mbed_connect_step3(struct connectdata *conn, + + /* If there's already a matching session in the cache, delete it */ + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, NULL, sockindex)) ++ if(!Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, sockindex)) + Curl_ssl_delsessionid(conn, old_ssl_sessionid); + +- retcode = Curl_ssl_addsessionid(conn, isproxy, our_ssl_sessionid, 0, sockindex); ++ retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid, 0, sockindex); + Curl_ssl_sessionid_unlock(conn); + if(retcode) { + mbedtls_ssl_session_free(our_ssl_sessionid); +diff --git a/lib/vtls/mesalink.c b/lib/vtls/mesalink.c +index 79d1e3d..cab1e39 100644 +--- a/lib/vtls/mesalink.c ++++ b/lib/vtls/mesalink.c +@@ -263,8 +263,7 @@ mesalink_connect_step1(struct connectdata *conn, int sockindex) + void *ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + Curl_ssl_sessionid_unlock(conn); +@@ -348,14 +347,12 @@ mesalink_connect_step3(struct connectdata *conn, int sockindex) + bool incache; + SSL_SESSION *our_ssl_sessionid; + void *old_ssl_sessionid = NULL; +- bool inproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + our_ssl_sessionid = SSL_get_session(BACKEND->handle); + + Curl_ssl_sessionid_lock(conn); + incache = +- !(Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, +- NULL, sockindex)); ++ !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, sockindex)); + if(incache) { + if(old_ssl_sessionid != our_ssl_sessionid) { + infof(data, "old SSL session ID is stale, removing\n"); +@@ -366,7 +363,7 @@ mesalink_connect_step3(struct connectdata *conn, int sockindex) + + if(!incache) { + result = Curl_ssl_addsessionid( +- conn, isproxy, our_ssl_sessionid, 0 /* unknown size */, sockindex); ++ conn, our_ssl_sessionid, 0 /* unknown size */, sockindex); + if(result) { + Curl_ssl_sessionid_unlock(conn); + failf(data, "failed to store ssl session"); +diff --git a/lib/vtls/nss.c b/lib/vtls/nss.c +index af8706c..ef51b0d 100644 +--- a/lib/vtls/nss.c ++++ b/lib/vtls/nss.c +@@ -950,9 +950,6 @@ static void display_cert_info(struct Curl_easy *data, + PR_Free(common_name); + } + +-/* A number of certs that will never occur in a real server handshake */ +-#define TOO_MANY_CERTS 300 +- + static CURLcode display_conn_info(struct connectdata *conn, PRFileDesc *sock) + { + CURLcode result = CURLE_OK; +@@ -989,11 +986,6 @@ static CURLcode display_conn_info(struct connectdata *conn, PRFileDesc *sock) + cert2 = CERT_FindCertIssuer(cert, now, certUsageSSLCA); + while(cert2) { + i++; +- if(i >= TOO_MANY_CERTS) { +- CERT_DestroyCertificate(cert2); +- failf(conn->data, "certificate loop"); +- return CURLE_SSL_CERTPROBLEM; +- } + if(cert2->isRoot) { + CERT_DestroyCertificate(cert2); + break; +@@ -1955,13 +1947,13 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex) + } + } + +- if(SSL_SET_OPTION(primary.CRLfile)) { +- const CURLcode rv = nss_load_crl(SSL_SET_OPTION(primary.CRLfile)); ++ if(SSL_SET_OPTION(CRLfile)) { ++ const CURLcode rv = nss_load_crl(SSL_SET_OPTION(CRLfile)); + if(rv) { + result = rv; + goto error; + } +- infof(data, " CRLfile: %s\n", SSL_SET_OPTION(primary.CRLfile)); ++ infof(data, " CRLfile: %s\n", SSL_SET_OPTION(CRLfile)); + } + + if(SSL_SET_OPTION(cert)) { +@@ -2159,9 +2151,9 @@ static CURLcode nss_do_connect(struct connectdata *conn, int sockindex) + if(result) + goto error; + +- if(SSL_CONN_CONFIG(issuercert)) { ++ if(SSL_SET_OPTION(issuercert)) { + SECStatus ret = SECFailure; +- char *nickname = dup_nickname(data, SSL_CONN_CONFIG(issuercert)); ++ char *nickname = dup_nickname(data, SSL_SET_OPTION(issuercert)); + if(nickname) { + /* we support only nicknames in case of issuercert for now */ + ret = check_issuer_cert(BACKEND->handle, nickname); +diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c +index 23f9ce0..726ff6e 100644 +--- a/lib/vtls/openssl.c ++++ b/lib/vtls/openssl.c +@@ -422,23 +422,12 @@ static int ossl_get_ssl_conn_index(void) + */ + static int ossl_get_ssl_sockindex_index(void) + { +- static int sockindex_index = -1; +- if(sockindex_index < 0) { +- sockindex_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); ++ static int ssl_ex_data_sockindex_index = -1; ++ if(ssl_ex_data_sockindex_index < 0) { ++ ssl_ex_data_sockindex_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, ++ NULL); + } +- return sockindex_index; +-} +- +-/* Return an extra data index for proxy boolean. +- * This index can be used with SSL_get_ex_data() and SSL_set_ex_data(). +- */ +-static int ossl_get_proxy_index(void) +-{ +- static int proxy_index = -1; +- if(proxy_index < 0) { +- proxy_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); +- } +- return proxy_index; ++ return ssl_ex_data_sockindex_index; + } + + static int passwd_callback(char *buf, int num, int encrypting, +@@ -1036,21 +1025,6 @@ static int Curl_ossl_init(void) + char *keylog_file_name; + #endif + +-#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \ +- !defined(LIBRESSL_VERSION_NUMBER) +- const uint64_t flags = +-#ifdef OPENSSL_INIT_ENGINE_ALL_BUILTIN +- /* not present in BoringSSL */ +- OPENSSL_INIT_ENGINE_ALL_BUILTIN | +-#endif +-#ifdef CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG +- OPENSSL_INIT_NO_LOAD_CONFIG | +-#else +- OPENSSL_INIT_LOAD_CONFIG | +-#endif +- 0; +- OPENSSL_init_ssl(flags, NULL); +-#else + OPENSSL_load_builtin_modules(); + + #ifdef USE_OPENSSL_ENGINE +@@ -1069,6 +1043,10 @@ static int Curl_ossl_init(void) + CONF_MFLAGS_IGNORE_MISSING_FILE); + #endif + ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \ ++ !defined(LIBRESSL_VERSION_NUMBER) ++ /* OpenSSL 1.1.0+ takes care of initialization itself */ ++#else + /* Lets get nice error messages */ + SSL_load_error_strings(); + +@@ -1101,8 +1079,7 @@ static int Curl_ossl_init(void) + #endif + + /* Initialize the extra data indexes */ +- if(ossl_get_ssl_conn_index() < 0 || ossl_get_ssl_sockindex_index() < 0 || +- ossl_get_proxy_index() < 0) ++ if(ossl_get_ssl_conn_index() < 0 || ossl_get_ssl_sockindex_index() < 0) + return 0; + + return 1; +@@ -1740,11 +1717,6 @@ static CURLcode verifystatus(struct connectdata *conn, + OCSP_BASICRESP *br = NULL; + X509_STORE *st = NULL; + STACK_OF(X509) *ch = NULL; +- X509 *cert; +- OCSP_CERTID *id = NULL; +- int cert_status, crl_reason; +- ASN1_GENERALIZEDTIME *rev, *thisupd, *nextupd; +- int ret; + + long len = SSL_get_tlsext_status_ocsp_resp(BACKEND->handle, &status); + +@@ -1813,63 +1785,43 @@ static CURLcode verifystatus(struct connectdata *conn, + goto end; + } + +- /* Compute the certificate's ID */ +- cert = SSL_get_peer_certificate(BACKEND->handle); +- if(!cert) { +- failf(data, "Error getting peer certficate"); +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; +- } ++ for(i = 0; i < OCSP_resp_count(br); i++) { ++ int cert_status, crl_reason; ++ OCSP_SINGLERESP *single = NULL; + +- for(i = 0; i < sk_X509_num(ch); i++) { +- X509 *issuer = sk_X509_value(ch, i); +- if(X509_check_issued(issuer, cert) == X509_V_OK) { +- id = OCSP_cert_to_id(EVP_sha1(), cert, issuer); +- break; +- } +- } +- X509_free(cert); ++ ASN1_GENERALIZEDTIME *rev, *thisupd, *nextupd; + +- if(!id) { +- failf(data, "Error computing OCSP ID"); +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; +- } ++ single = OCSP_resp_get0(br, i); ++ if(!single) ++ continue; + +- /* Find the single OCSP response corresponding to the certificate ID */ +- ret = OCSP_resp_find_status(br, id, &cert_status, &crl_reason, &rev, +- &thisupd, &nextupd); +- OCSP_CERTID_free(id); +- if(ret != 1) { +- failf(data, "Could not find certificate ID in OCSP response"); +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; +- } ++ cert_status = OCSP_single_get0_status(single, &crl_reason, &rev, ++ &thisupd, &nextupd); + +- /* Validate the corresponding single OCSP response */ +- if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)) { +- failf(data, "OCSP response has expired"); +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; +- } ++ if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)) { ++ failf(data, "OCSP response has expired"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- infof(data, "SSL certificate status: %s (%d)\n", +- OCSP_cert_status_str(cert_status), cert_status); ++ infof(data, "SSL certificate status: %s (%d)\n", ++ OCSP_cert_status_str(cert_status), cert_status); + +- switch(cert_status) { +- case V_OCSP_CERTSTATUS_GOOD: +- break; ++ switch(cert_status) { ++ case V_OCSP_CERTSTATUS_GOOD: ++ break; + +- case V_OCSP_CERTSTATUS_REVOKED: +- result = CURLE_SSL_INVALIDCERTSTATUS; +- failf(data, "SSL certificate revocation reason: %s (%d)", +- OCSP_crl_reason_str(crl_reason), crl_reason); +- goto end; ++ case V_OCSP_CERTSTATUS_REVOKED: ++ result = CURLE_SSL_INVALIDCERTSTATUS; + +- case V_OCSP_CERTSTATUS_UNKNOWN: +- default: +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; ++ failf(data, "SSL certificate revocation reason: %s (%d)", ++ OCSP_crl_reason_str(crl_reason), crl_reason); ++ goto end; ++ ++ case V_OCSP_CERTSTATUS_UNKNOWN: ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + } + + end: +@@ -2390,10 +2342,8 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + curl_socket_t *sockindex_ptr; + int connectdata_idx = ossl_get_ssl_conn_index(); + int sockindex_idx = ossl_get_ssl_sockindex_index(); +- int proxy_idx = ossl_get_proxy_index(); +- bool isproxy; + +- if(connectdata_idx < 0 || sockindex_idx < 0 || proxy_idx < 0) ++ if(connectdata_idx < 0 || sockindex_idx < 0) + return 0; + + conn = (struct connectdata*) SSL_get_ex_data(ssl, connectdata_idx); +@@ -2406,18 +2356,13 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + sockindex_ptr = (curl_socket_t*) SSL_get_ex_data(ssl, sockindex_idx); + sockindex = (int)(sockindex_ptr - conn->sock); + +- isproxy = SSL_get_ex_data(ssl, proxy_idx) ? TRUE : FALSE; +- + if(SSL_SET_OPTION(primary.sessionid)) { + bool incache; + void *old_ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(isproxy) +- incache = FALSE; +- else +- incache = !(Curl_ssl_getsessionid(conn, isproxy, +- &old_ssl_sessionid, NULL, sockindex)); ++ incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, ++ sockindex)); + if(incache) { + if(old_ssl_sessionid != ssl_sessionid) { + infof(data, "old SSL session ID is stale, removing\n"); +@@ -2427,7 +2372,7 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + } + + if(!incache) { +- if(!Curl_ssl_addsessionid(conn, isproxy, ssl_sessionid, ++ if(!Curl_ssl_addsessionid(conn, ssl_sessionid, + 0 /* unknown size */, sockindex)) { + /* the session has been put into the session cache */ + res = 1; +@@ -2466,14 +2411,14 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + &data->set.proxy_ssl.certverifyresult : &data->set.ssl.certverifyresult; + const long int ssl_version = SSL_CONN_CONFIG(version); + #ifdef USE_TLS_SRP +- const enum CURL_TLSAUTH ssl_authtype = SSL_SET_OPTION(primary.authtype); ++ const enum CURL_TLSAUTH ssl_authtype = SSL_SET_OPTION(authtype); + #endif + char * const ssl_cert = SSL_SET_OPTION(cert); + const char * const ssl_cert_type = SSL_SET_OPTION(cert_type); + const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile); + const char * const ssl_capath = SSL_CONN_CONFIG(CApath); + const bool verifypeer = SSL_CONN_CONFIG(verifypeer); +- const char * const ssl_crlfile = SSL_SET_OPTION(primary.CRLfile); ++ const char * const ssl_crlfile = SSL_SET_OPTION(CRLfile); + char error_buffer[256]; + + DEBUGASSERT(ssl_connect_1 == connssl->connecting_state); +@@ -2752,15 +2697,15 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + + #ifdef USE_TLS_SRP + if(ssl_authtype == CURL_TLSAUTH_SRP) { +- char * const ssl_username = SSL_SET_OPTION(primary.username); +- char * const ssl_password = SSL_SET_OPTION(primary.password); ++ char * const ssl_username = SSL_SET_OPTION(username); ++ + infof(data, "Using TLS-SRP username: %s\n", ssl_username); + + if(!SSL_CTX_set_srp_username(BACKEND->ctx, ssl_username)) { + failf(data, "Unable to set SRP user name"); + return CURLE_BAD_FUNCTION_ARGUMENT; + } +- if(!SSL_CTX_set_srp_password(BACKEND->ctx, ssl_password)) { ++ if(!SSL_CTX_set_srp_password(BACKEND->ctx, SSL_SET_OPTION(password))) { + failf(data, "failed setting SRP password"); + return CURLE_BAD_FUNCTION_ARGUMENT; + } +@@ -2924,25 +2869,16 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + void *ssl_sessionid = NULL; + int connectdata_idx = ossl_get_ssl_conn_index(); + int sockindex_idx = ossl_get_ssl_sockindex_index(); +- int proxy_idx = ossl_get_proxy_index(); + +- if(connectdata_idx >= 0 && sockindex_idx >= 0 && proxy_idx >= 0) { ++ if(connectdata_idx >= 0 && sockindex_idx >= 0) { + /* Store the data needed for the "new session" callback. + * The sockindex is stored as a pointer to an array element. */ + SSL_set_ex_data(BACKEND->handle, connectdata_idx, conn); + SSL_set_ex_data(BACKEND->handle, sockindex_idx, conn->sock + sockindex); +-#ifndef CURL_DISABLE_PROXY +- SSL_set_ex_data(BACKEND->handle, proxy_idx, SSL_IS_PROXY() ? (void *) 1: +- NULL); +-#else +- SSL_set_ex_data(BACKEND->handle, proxy_idx, NULL); +-#endif +- + } + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + Curl_ssl_sessionid_unlock(conn); +@@ -3603,7 +3539,7 @@ static CURLcode servercert(struct connectdata *conn, + deallocating the certificate. */ + + /* e.g. match issuer name with provided issuer certificate */ +- if(SSL_CONN_CONFIG(issuercert)) { ++ if(SSL_SET_OPTION(issuercert)) { + fp = BIO_new(BIO_s_file()); + if(fp == NULL) { + failf(data, +@@ -3616,10 +3552,10 @@ static CURLcode servercert(struct connectdata *conn, + return CURLE_OUT_OF_MEMORY; + } + +- if(BIO_read_filename(fp, SSL_CONN_CONFIG(issuercert)) <= 0) { ++ if(BIO_read_filename(fp, SSL_SET_OPTION(issuercert)) <= 0) { + if(strict) + failf(data, "SSL: Unable to open issuer cert (%s)", +- SSL_CONN_CONFIG(issuercert)); ++ SSL_SET_OPTION(issuercert)); + BIO_free(fp); + X509_free(BACKEND->server_cert); + BACKEND->server_cert = NULL; +@@ -3630,7 +3566,7 @@ static CURLcode servercert(struct connectdata *conn, + if(!issuer) { + if(strict) + failf(data, "SSL: Unable to read issuer cert (%s)", +- SSL_CONN_CONFIG(issuercert)); ++ SSL_SET_OPTION(issuercert)); + BIO_free(fp); + X509_free(issuer); + X509_free(BACKEND->server_cert); +@@ -3641,7 +3577,7 @@ static CURLcode servercert(struct connectdata *conn, + if(X509_check_issued(issuer, BACKEND->server_cert) != X509_V_OK) { + if(strict) + failf(data, "SSL: Certificate issuer check failed (%s)", +- SSL_CONN_CONFIG(issuercert)); ++ SSL_SET_OPTION(issuercert)); + BIO_free(fp); + X509_free(issuer); + X509_free(BACKEND->server_cert); +@@ -3650,7 +3586,7 @@ static CURLcode servercert(struct connectdata *conn, + } + + infof(data, " SSL certificate issuer check ok (%s)\n", +- SSL_CONN_CONFIG(issuercert)); ++ SSL_SET_OPTION(issuercert)); + BIO_free(fp); + X509_free(issuer); + } +diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c +index f0aa727..dc58ed0 100644 +--- a/lib/vtls/schannel.c ++++ b/lib/vtls/schannel.c +@@ -497,8 +497,7 @@ schannel_connect_step1(struct connectdata *conn, int sockindex) + /* check for an existing re-usable credential handle */ + if(SSL_SET_OPTION(primary.sessionid)) { + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- (void **)&old_cred, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL, sockindex)) { + BACKEND->cred = old_cred; + DEBUGF(infof(data, "schannel: re-using existing credential handle\n")); + +@@ -1204,9 +1203,8 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + struct ssl_connect_data *connssl = &conn->ssl[sockindex]; + SECURITY_STATUS sspi_status = SEC_E_OK; + CERT_CONTEXT *ccert_context = NULL; +- bool isproxy = SSL_IS_PROXY(); + #ifdef DEBUGBUILD +- const char * const hostname = isproxy ? conn->http_proxy.host.name : ++ const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name : + conn->host.name; + #endif + #ifdef HAS_ALPN +@@ -1280,7 +1278,7 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + struct curl_schannel_cred *old_cred = NULL; + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, isproxy, (void **)&old_cred, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL, + sockindex)); + if(incache) { + if(old_cred != BACKEND->cred) { +@@ -1292,7 +1290,7 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + } + } + if(!incache) { +- result = Curl_ssl_addsessionid(conn, isproxy, (void *)BACKEND->cred, ++ result = Curl_ssl_addsessionid(conn, (void *)BACKEND->cred, + sizeof(struct curl_schannel_cred), + sockindex); + if(result) { +diff --git a/lib/vtls/sectransp.c b/lib/vtls/sectransp.c +index 1c05607..4eece89 100644 +--- a/lib/vtls/sectransp.c ++++ b/lib/vtls/sectransp.c +@@ -1376,8 +1376,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile); + const bool verifypeer = SSL_CONN_CONFIG(verifypeer); + char * const ssl_cert = SSL_SET_OPTION(cert); +- bool isproxy = SSL_IS_PROXY(); +- const char * const hostname = isproxy ? conn->http_proxy.host.name : ++ const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name : + conn->host.name; + const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port; + #ifdef ENABLE_IPV6 +@@ -1585,7 +1584,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + + #ifdef USE_NGHTTP2 + if(data->set.httpversion >= CURL_HTTP_VERSION_2 && +- (!isproxy || !conn->bits.tunnel_proxy)) { ++ (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)) { + CFArrayAppendValue(alpnArr, CFSTR(NGHTTP2_PROTO_VERSION_ID)); + infof(data, "ALPN, offering %s\n", NGHTTP2_PROTO_VERSION_ID); + } +@@ -1917,7 +1916,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + size_t ssl_sessionid_len; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, isproxy, (void **)&ssl_sessionid, ++ if(!Curl_ssl_getsessionid(conn, (void **)&ssl_sessionid, + &ssl_sessionid_len, sockindex)) { + /* we got a session id, use it! */ + err = SSLSetPeerID(BACKEND->ssl_ctx, ssl_sessionid, ssl_sessionid_len); +@@ -1945,7 +1944,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + return CURLE_SSL_CONNECT_ERROR; + } + +- result = Curl_ssl_addsessionid(conn, isproxy, ssl_sessionid, ssl_sessionid_len, ++ result = Curl_ssl_addsessionid(conn, ssl_sessionid, ssl_sessionid_len, + sockindex); + Curl_ssl_sessionid_unlock(conn); + if(result) { +diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c +index 557c8d3..c493b15 100644 +--- a/lib/vtls/vtls.c ++++ b/lib/vtls/vtls.c +@@ -82,40 +82,22 @@ + else \ + dest->var = NULL; + +-static bool safecmp(char *a, char *b) +-{ +- if(a && b) +- return !strcmp(a, b); +- else if(!a && !b) +- return TRUE; /* match */ +- return FALSE; /* no match */ +-} +- +- + bool + Curl_ssl_config_matches(struct ssl_primary_config* data, + struct ssl_primary_config* needle) + { + if((data->version == needle->version) && + (data->version_max == needle->version_max) && +- (data->ssl_options == needle->ssl_options) && + (data->verifypeer == needle->verifypeer) && + (data->verifyhost == needle->verifyhost) && + (data->verifystatus == needle->verifystatus) && +- safecmp(data->CApath, needle->CApath) && +- safecmp(data->CAfile, needle->CAfile) && +- safecmp(data->issuercert, needle->issuercert) && +- safecmp(data->clientcert, needle->clientcert) && +- safecmp(data->random_file, needle->random_file) && +- safecmp(data->egdsocket, needle->egdsocket) && +-#ifdef USE_TLS_SRP +- Curl_safecmp(data->username, needle->username) && +- Curl_safecmp(data->password, needle->password) && +- (data->authtype == needle->authtype) && +-#endif ++ Curl_safe_strcasecompare(data->CApath, needle->CApath) && ++ Curl_safe_strcasecompare(data->CAfile, needle->CAfile) && ++ Curl_safe_strcasecompare(data->clientcert, needle->clientcert) && ++ Curl_safe_strcasecompare(data->random_file, needle->random_file) && ++ Curl_safe_strcasecompare(data->egdsocket, needle->egdsocket) && + Curl_safe_strcasecompare(data->cipher_list, needle->cipher_list) && + Curl_safe_strcasecompare(data->cipher_list13, needle->cipher_list13) && +- Curl_safe_strcasecompare(data->CRLfile, needle->CRLfile) && + Curl_safe_strcasecompare(data->pinned_key, needle->pinned_key)) + return TRUE; + +@@ -132,25 +114,15 @@ Curl_clone_primary_ssl_config(struct ssl_primary_config *source, + dest->verifyhost = source->verifyhost; + dest->verifystatus = source->verifystatus; + dest->sessionid = source->sessionid; +- dest->ssl_options = source->ssl_options; +-#ifdef USE_TLS_SRP +- dest->authtype = source->authtype; +-#endif + + CLONE_STRING(CApath); + CLONE_STRING(CAfile); +- CLONE_STRING(issuercert); + CLONE_STRING(clientcert); + CLONE_STRING(random_file); + CLONE_STRING(egdsocket); + CLONE_STRING(cipher_list); + CLONE_STRING(cipher_list13); + CLONE_STRING(pinned_key); +- CLONE_STRING(CRLfile); +-#ifdef USE_TLS_SRP +- CLONE_STRING(username); +- CLONE_STRING(password); +-#endif + + return TRUE; + } +@@ -159,18 +131,12 @@ void Curl_free_primary_ssl_config(struct ssl_primary_config* sslc) + { + Curl_safefree(sslc->CApath); + Curl_safefree(sslc->CAfile); +- Curl_safefree(sslc->issuercert); + Curl_safefree(sslc->clientcert); + Curl_safefree(sslc->random_file); + Curl_safefree(sslc->egdsocket); + Curl_safefree(sslc->cipher_list); + Curl_safefree(sslc->cipher_list13); + Curl_safefree(sslc->pinned_key); +- Curl_safefree(sslc->CRLfile); +-#ifdef USE_TLS_SRP +- Curl_safefree(sslc->username); +- Curl_safefree(sslc->password); +-#endif + } + + #ifdef USE_SSL +@@ -339,7 +305,6 @@ void Curl_ssl_sessionid_unlock(struct connectdata *conn) + * there's one suitable, it is provided. Returns TRUE when no entry matched. + */ + bool Curl_ssl_getsessionid(struct connectdata *conn, +- const bool isProxy, + void **ssl_sessionid, + size_t *idsize, /* set 0 if unknown */ + int sockindex) +@@ -350,6 +315,7 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + long *general_age; + bool no_match = TRUE; + ++ const bool isProxy = CONNECT_PROXY_SSL(); + struct ssl_primary_config * const ssl_config = isProxy ? + &conn->proxy_ssl_config : + &conn->ssl_config; +@@ -358,11 +324,6 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + int port = isProxy ? (int)conn->port : conn->remote_port; + *ssl_sessionid = NULL; + +-#ifdef CURL_DISABLE_PROXY +- if(isProxy) +- return TRUE; +-#endif +- + DEBUGASSERT(SSL_SET_OPTION(primary.sessionid)); + + if(!SSL_SET_OPTION(primary.sessionid)) +@@ -450,7 +411,6 @@ void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid) + * later on. + */ + CURLcode Curl_ssl_addsessionid(struct connectdata *conn, +- bool isProxy, + void *ssl_sessionid, + size_t idsize, + int sockindex) +@@ -463,6 +423,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn, + char *clone_conn_to_host; + int conn_to_port; + long *general_age; ++ const bool isProxy = CONNECT_PROXY_SSL(); + struct ssl_primary_config * const ssl_config = isProxy ? + &conn->proxy_ssl_config : + &conn->ssl_config; +diff --git a/lib/vtls/vtls.h b/lib/vtls/vtls.h +index 9fed5a0..976cc43 100644 +--- a/lib/vtls/vtls.h ++++ b/lib/vtls/vtls.h +@@ -203,7 +203,6 @@ void Curl_ssl_sessionid_unlock(struct connectdata *conn); + * under sessionid mutex). + */ + bool Curl_ssl_getsessionid(struct connectdata *conn, +- const bool isproxy, + void **ssl_sessionid, + size_t *idsize, /* set 0 if unknown */ + int sockindex); +@@ -213,7 +212,6 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + * object with cache (e.g. incrementing refcount on success) + */ + CURLcode Curl_ssl_addsessionid(struct connectdata *conn, +- const bool isProxy, + void *ssl_sessionid, + size_t idsize, + int sockindex); +diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c +index c772bd5..890bcbf 100644 +--- a/lib/vtls/wolfssl.c ++++ b/lib/vtls/wolfssl.c +@@ -392,8 +392,7 @@ wolfssl_connect_step1(struct connectdata *conn, + void *ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, +- &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + char error_buffer[WOLFSSL_MAX_ERROR_SZ]; +@@ -619,10 +618,9 @@ wolfssl_connect_step3(struct connectdata *conn, + void *old_ssl_sessionid = NULL; + + our_ssl_sessionid = SSL_get_session(BACKEND->handle); +- bool isproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, + sockindex)); + if(incache) { + if(old_ssl_sessionid != our_ssl_sessionid) { +@@ -633,7 +631,7 @@ wolfssl_connect_step3(struct connectdata *conn, + } + + if(!incache) { +- result = Curl_ssl_addsessionid(conn, isproxy, our_ssl_sessionid, ++ result = Curl_ssl_addsessionid(conn, our_ssl_sessionid, + 0 /* unknown size */, sockindex); + if(result) { + Curl_ssl_sessionid_unlock(conn); +diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c +index e0784c6..77224ad 100644 +--- a/src/tool_cb_hdr.c ++++ b/src/tool_cb_hdr.c +@@ -188,11 +188,25 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata) + filename = parse_filename(p, len); + if(filename) { + if(outs->stream) { +- /* indication of problem, get out! */ +- free(filename); +- return failure; ++ int rc; ++ /* already opened and possibly written to */ ++ if(outs->fopened) ++ fclose(outs->stream); ++ outs->stream = NULL; ++ ++ /* rename the initial file name to the new file name */ ++ rc = rename(outs->filename, filename); ++ if(rc != 0) { ++ warnf(outs->config->global, "Failed to rename %s -> %s: %s\n", ++ outs->filename, filename, strerror(errno)); ++ } ++ if(outs->alloc_filename) ++ Curl_safefree(outs->filename); ++ if(rc != 0) { ++ free(filename); ++ return failure; ++ } + } +- + outs->is_cd_filename = TRUE; + outs->s_isreg = TRUE; + outs->fopened = FALSE; +diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c +index d492b58..f802a5a 100644 +--- a/src/tool_cfgable.c ++++ b/src/tool_cfgable.c +@@ -44,7 +44,6 @@ void config_init(struct OperationConfig* config) + config->tcp_nodelay = TRUE; /* enabled by default */ + config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT; + config->http09_allowed = FALSE; +- config->ftp_skip_ip = TRUE; + } + + static void free_config_fields(struct OperationConfig *config) +diff --git a/src/tool_getparam.c b/src/tool_getparam.c +index 8191ed5..8df6e5e 100644 +--- a/src/tool_getparam.c ++++ b/src/tool_getparam.c +@@ -1800,11 +1800,6 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ + } + break; + case 'i': +- if(config->content_disposition) { +- warnf(global, +- "--include and --remote-header-name cannot be combined.\n"); +- return PARAM_BAD_USE; +- } + config->show_headers = toggle; /* show the headers as well in the + general output stream */ + break; +diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc +index 52bdaec..09cb057 100644 +--- a/tests/data/Makefile.inc ++++ b/tests/data/Makefile.inc +@@ -111,11 +111,6 @@ test936 test937 test938 test939 test940 test941 test942 test943 test944 \ + test945 test946 test947 test948 test949 test950 test951 test952 test953 \ + test954 \ + \ +-test973 test974 test975 test976 \ +-test980 test981 test982 test983 \ +-\ +-test984 test985 test986 \ +-\ + test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 \ + test1008 test1009 test1010 test1011 test1012 test1013 test1014 test1015 \ + test1016 test1017 test1018 test1019 test1020 test1021 test1022 test1023 \ +@@ -136,7 +131,7 @@ test1128 test1129 test1130 test1131 test1132 test1133 test1134 test1135 \ + test1136 test1137 test1138 test1139 test1140 test1141 test1142 test1143 \ + test1144 test1145 test1146 test1147 test1148 test1149 test1150 test1151 \ + test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 \ +-test1160 test1161 test1162 test1163 test1164 test1165 test1166 test1168 \ ++test1160 test1161 test1162 test1163 test1164 test1165 test1166 \ + test1170 test1171 test1172 test1173 test1174 test1175 \ + \ + test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \ +diff --git a/tests/data/test1168 b/tests/data/test1168 +deleted file mode 100644 +index 283e91e..0000000 +--- a/tests/data/test1168 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-HTTP +-HTTP GET +-followlocation +- +- +-# Server-side +- +- +-HTTP/1.1 301 This is a weirdo text message swsclose +-Date: Thu, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Location: /data/11680002.txt +-Connection: close +- +-This server reply is for testing a simple Location: following +- +- +- +-HTTP/1.1 200 Followed here fine swsclose +-Date: Thu, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 52 +- +-If this is received, the location following worked +- +- +- +-HTTP/1.1 301 This is a weirdo text message swsclose +-Date: Thu, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Location: /data/11680002.txt +-Connection: close +- +-HTTP/1.1 200 Followed here fine swsclose +-Date: Thu, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 52 +- +-If this is received, the location following worked +- +- +- +- +-# Client-side +- +- +-http +- +- +-HTTP redirect with credentials using # in user and password +- +- +-http://%HOSTIP:%HTTPPORT/want/1168 -L -u "catmai#d:#DZaRJYrixKE*gFY" +- +- +- +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /want/1168 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Authorization: Basic Y2F0bWFpI2Q6I0RaYVJKWXJpeEtFKmdGWQ== +-Accept: */* +- +-GET /data/11680002.txt HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Authorization: Basic Y2F0bWFpI2Q6I0RaYVJKWXJpeEtFKmdGWQ== +-Accept: */* +- +- +- +- +diff --git a/tests/data/test1400 b/tests/data/test1400 +index ade50d4..c0d409b 100644 +--- a/tests/data/test1400 ++++ b/tests/data/test1400 +@@ -76,7 +76,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1401 b/tests/data/test1401 +index a2e9ef2..ec3b25c 100644 +--- a/tests/data/test1401 ++++ b/tests/data/test1401 +@@ -90,7 +90,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_COOKIE, "chocolate=chip"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(hnd, CURLOPT_PROTOCOLS, (long)CURLPROTO_FILE | + (long)CURLPROTO_FTP | +diff --git a/tests/data/test1402 b/tests/data/test1402 +index 99d4b70..bf7eb7b 100644 +--- a/tests/data/test1402 ++++ b/tests/data/test1402 +@@ -81,7 +81,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1403 b/tests/data/test1403 +index 90f9b4e..731d274 100644 +--- a/tests/data/test1403 ++++ b/tests/data/test1403 +@@ -76,7 +76,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1404 b/tests/data/test1404 +index d351c3e..d3c66a9 100644 +--- a/tests/data/test1404 ++++ b/tests/data/test1404 +@@ -147,7 +147,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1405 b/tests/data/test1405 +index d1ebb7c..dcc8f80 100644 +--- a/tests/data/test1405 ++++ b/tests/data/test1405 +@@ -89,7 +89,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_POSTQUOTE, slist2); + curl_easy_setopt(hnd, CURLOPT_PREQUOTE, slist3); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1406 b/tests/data/test1406 +index 31db82a..8803c84 100644 +--- a/tests/data/test1406 ++++ b/tests/data/test1406 +@@ -79,7 +79,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_URL, "smtp://%HOSTIP:%SMTPPORT/1406"); + curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(hnd, CURLOPT_MAIL_FROM, "sender@example.com"); + curl_easy_setopt(hnd, CURLOPT_MAIL_RCPT, slist1); +diff --git a/tests/data/test1407 b/tests/data/test1407 +index d329509..917a5de 100644 +--- a/tests/data/test1407 ++++ b/tests/data/test1407 +@@ -62,7 +62,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_DIRLISTONLY, 1L); + curl_easy_setopt(hnd, CURLOPT_USERPWD, "user:secret"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1420 b/tests/data/test1420 +index c1ba190..03c4584 100644 +--- a/tests/data/test1420 ++++ b/tests/data/test1420 +@@ -67,7 +67,6 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_URL, "imap://%HOSTIP:%IMAPPORT/1420/;MAILINDEX=1"); + curl_easy_setopt(hnd, CURLOPT_USERPWD, "user:secret"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); +- curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test973 b/tests/data/test973 +deleted file mode 100644 +index e2f051d..0000000 +--- a/tests/data/test973 ++++ /dev/null +@@ -1,88 +0,0 @@ +- +- +- +-HTTP +-FTP +---location +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 301 redirect +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 0 +-Connection: close +-Content-Type: text/html +-Location: ftp://127.0.0.1:8992/a/path/9730002 +- +- +- +-data +- to +- see +-that FTP +-works +- so does it? +- +- +- +-HTTP/1.1 301 redirect +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 0 +-Connection: close +-Content-Type: text/html +-Location: ftp://127.0.0.1:8992/a/path/9730002 +- +-data +- to +- see +-that FTP +-works +- so does it? +- +- +- +- +-# +-# Client-side +- +- +-http +-ftp +- +- +-HTTP with auth redirected to FTP w/o auth +- +- +-http://%HOSTIP:%HTTPPORT/973 -L -u joe:secret +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-GET /973 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Authorization: Basic am9lOnNlY3JldA== +-User-Agent: curl/7.68.0 +-Accept: */* +- +-USER anonymous +-PASS ftp@example.com +-PWD +-CWD a +-CWD path +-EPSV +-TYPE I +-SIZE 9730002 +-RETR 9730002 +-QUIT +- +- +- +diff --git a/tests/data/test974 b/tests/data/test974 +deleted file mode 100644 +index 854200a..0000000 +--- a/tests/data/test974 ++++ /dev/null +@@ -1,87 +0,0 @@ +- +- +- +-HTTP +---location +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 301 redirect +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 0 +-Connection: close +-Content-Type: text/html +-Location: http://firsthost.974:9999/a/path/9740002 +- +- +- +-HTTP/1.1 200 OK +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 4 +-Connection: close +-Content-Type: text/html +- +-hey +- +- +- +-HTTP/1.1 301 redirect +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 0 +-Connection: close +-Content-Type: text/html +-Location: http://firsthost.974:9999/a/path/9740002 +- +-HTTP/1.1 200 OK +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 4 +-Connection: close +-Content-Type: text/html +- +-hey +- +- +- +- +-# +-# Client-side +- +- +-http +- +- +-HTTP with auth redirected to HTTP on a diff port w/o auth +- +- +--x http://%HOSTIP:%HTTPPORT http://firsthost.974 -L -u joe:secret +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-GET http://firsthost.974/ HTTP/1.1 +-Host: firsthost.974 +-Authorization: Basic am9lOnNlY3JldA== +-User-Agent: curl/7.68.0 +-Accept: */* +-Proxy-Connection: Keep-Alive +- +-GET http://firsthost.974:9999/a/path/9740002 HTTP/1.1 +-Host: firsthost.974:9999 +-User-Agent: curl/7.68.0 +-Accept: */* +-Proxy-Connection: Keep-Alive +- +- +- +- +diff --git a/tests/data/test975 b/tests/data/test975 +deleted file mode 100644 +index 2ab23e9..0000000 +--- a/tests/data/test975 ++++ /dev/null +@@ -1,88 +0,0 @@ +- +- +- +-HTTP +-FTP +---location-trusted +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 301 redirect +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 0 +-Connection: close +-Content-Type: text/html +-Location: ftp://127.0.0.1:8992/a/path/9750002 +- +- +- +-data +- to +- see +-that FTP +-works +- so does it? +- +- +- +-HTTP/1.1 301 redirect +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 0 +-Connection: close +-Content-Type: text/html +-Location: ftp://127.0.0.1:8992/a/path/9750002 +- +-data +- to +- see +-that FTP +-works +- so does it? +- +- +- +- +-# +-# Client-side +- +- +-http +-ftp +- +- +-HTTP with auth redirected to FTP allowing auth to continue +- +- +-http://%HOSTIP:%HTTPPORT/975 --location-trusted -u joe:secret +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-GET /975 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Authorization: Basic am9lOnNlY3JldA== +-User-Agent: curl/7.68.0 +-Accept: */* +- +-USER joe +-PASS secret +-PWD +-CWD a +-CWD path +-EPSV +-TYPE I +-SIZE 9750002 +-RETR 9750002 +-QUIT +- +- +- +diff --git a/tests/data/test976 b/tests/data/test976 +deleted file mode 100644 +index 65d51ce..0000000 +--- a/tests/data/test976 ++++ /dev/null +@@ -1,88 +0,0 @@ +- +- +- +-HTTP +---location-trusted +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 301 redirect +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 0 +-Connection: close +-Content-Type: text/html +-Location: http://firsthost.976:9999/a/path/9760002 +- +- +- +-HTTP/1.1 200 OK +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 4 +-Connection: close +-Content-Type: text/html +- +-hey +- +- +- +-HTTP/1.1 301 redirect +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 0 +-Connection: close +-Content-Type: text/html +-Location: http://firsthost.976:9999/a/path/9760002 +- +-HTTP/1.1 200 OK +-Date: Tue, 09 Nov 2010 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 4 +-Connection: close +-Content-Type: text/html +- +-hey +- +- +- +- +-# +-# Client-side +- +- +-http +- +- +-HTTP with auth redirected to HTTP on a diff port --location-trusted +- +- +--x http://%HOSTIP:%HTTPPORT http://firsthost.976 --location-trusted -u joe:secret +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-GET http://firsthost.976/ HTTP/1.1 +-Host: firsthost.976 +-Authorization: Basic am9lOnNlY3JldA== +-User-Agent: curl/7.68.0 +-Accept: */* +-Proxy-Connection: Keep-Alive +- +-GET http://firsthost.976:9999/a/path/9760002 HTTP/1.1 +-Host: firsthost.976:9999 +-Authorization: Basic am9lOnNlY3JldA== +-User-Agent: curl/7.68.0 +-Accept: */* +-Proxy-Connection: Keep-Alive +- +- +- +- +diff --git a/tests/data/test980 b/tests/data/test980 +deleted file mode 100644 +index 97567f8..0000000 +--- a/tests/data/test980 ++++ /dev/null +@@ -1,52 +0,0 @@ +- +- +- +-SMTP +-STARTTLS +- +- +- +-# +-# Server-side +- +- +-CAPA STARTTLS +-AUTH PLAIN +-REPLY STARTTLS 454 currently unavailable\r\n235 Authenticated\r\n250 2.1.0 Sender ok\r\n250 2.1.5 Recipient ok\r\n354 Enter mail\r\n250 2.0.0 Accepted +-REPLY AUTH 535 5.7.8 Authentication credentials invalid +- +- +- +-# +-# Client-side +- +- +-SSL +- +- +-smtp +- +- +-SMTP STARTTLS pipelined server response +- +- +-mail body +- +- +-smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -u user:secret --ssl --sasl-ir -T - +- +- +- +-# +-# Verify data after the test has been "shot" +- +-# 8 is CURLE_WEIRD_SERVER_REPLY +- +-8 +- +- +-EHLO %TESTNUMBER +-STARTTLS +- +- +- +diff --git a/tests/data/test981 b/tests/data/test981 +deleted file mode 100644 +index 2b98ce4..0000000 +--- a/tests/data/test981 ++++ /dev/null +@@ -1,59 +0,0 @@ +- +- +- +-IMAP +-STARTTLS +- +- +- +-# +-# Server-side +- +- +-CAPA STARTTLS +-REPLY STARTTLS A002 BAD currently unavailable\r\nA003 OK Authenticated\r\nA004 OK Accepted +-REPLY LOGIN A003 BAD Authentication credentials invalid +- +- +- +-# +-# Client-side +- +- +-SSL +- +- +-imap +- +- +-IMAP STARTTLS pipelined server response +- +- +-imap://%HOSTIP:%IMAPPORT/%TESTNUMBER -T log/upload%TESTNUMBER -u user:secret --ssl +- +- +-Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST) +-From: Fred Foobar +-Subject: afternoon meeting +-To: joe@example.com +-Message-Id: +-MIME-Version: 1.0 +-Content-Type: TEXT/PLAIN; CHARSET=US-ASCII +- +-Hello Joe, do you think we can meet at 3:30 tomorrow? +- +- +- +-# +-# Verify data after the test has been "shot" +- +-# 8 is CURLE_WEIRD_SERVER_REPLY +- +-8 +- +- +-A001 CAPABILITY +-A002 STARTTLS +- +- +- +diff --git a/tests/data/test982 b/tests/data/test982 +deleted file mode 100644 +index 9e07cc0..0000000 +--- a/tests/data/test982 ++++ /dev/null +@@ -1,57 +0,0 @@ +- +- +- +-POP3 +-STARTTLS +- +- +- +-# +-# Server-side +- +- +-CAPA STLS USER +-REPLY STLS -ERR currently unavailable\r\n+OK user accepted\r\n+OK authenticated +-REPLY PASS -ERR Authentication credentials invalid +- +- +-From: me@somewhere +-To: fake@nowhere +- +-body +- +--- +- yours sincerely +- +- +- +-# +-# Client-side +- +- +-SSL +- +- +-pop3 +- +- +-POP3 STARTTLS pipelined server response +- +- +-pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u user:secret --ssl +- +- +- +-# +-# Verify data after the test has been "shot" +- +-# 8 is CURLE_WEIRD_SERVER_REPLY +- +-8 +- +- +-CAPA +-STLS +- +- +- +diff --git a/tests/data/test983 b/tests/data/test983 +deleted file mode 100644 +index 300ec45..0000000 +--- a/tests/data/test983 ++++ /dev/null +@@ -1,52 +0,0 @@ +- +- +- +-FTP +-STARTTLS +- +- +- +-# +-# Server-side +- +- +-REPLY AUTH 500 unknown command\r\n500 unknown command\r\n331 give password\r\n230 Authenticated\r\n257 "/"\r\n200 OK\r\n200 OK\r\n200 OK\r\n226 Transfer complete +-REPLY PASS 530 Login incorrect +- +- +- +-# Client-side +- +- +-SSL +- +- +-ftp +- +- +-FTP STARTTLS pipelined server response +- +- +-data +- to +- see +-that FTPS +-works +- so does it? +- +- +---ssl --ftp-ssl-control ftp://%HOSTIP:%FTPPORT/%TESTNUMBER -T log/test%TESTNUMBER.txt -u user:secret -P %CLIENTIP +- +- +- +-# Verify data after the test has been "shot" +- +-# 8 is CURLE_WEIRD_SERVER_REPLY +- +-8 +- +- +-AUTH SSL +- +- +- +diff --git a/tests/data/test984 b/tests/data/test984 +deleted file mode 100644 +index e573f23..0000000 +--- a/tests/data/test984 ++++ /dev/null +@@ -1,56 +0,0 @@ +- +- +- +-IMAP +-STARTTLS +- +- +- +-# +-# Server-side +- +- +-REPLY CAPABILITY A001 BAD Not implemented +- +- +- +-# +-# Client-side +- +- +-SSL +- +- +-imap +- +- +-IMAP require STARTTLS with failing capabilities +- +- +-imap://%HOSTIP:%IMAPPORT/%TESTNUMBER -T log/upload%TESTNUMBER -u user:secret --ssl-reqd +- +- +-Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST) +-From: Fred Foobar +-Subject: afternoon meeting +-To: joe@example.com +-Message-Id: +-MIME-Version: 1.0 +-Content-Type: TEXT/PLAIN; CHARSET=US-ASCII +- +-Hello Joe, do you think we can meet at 3:30 tomorrow? +- +- +- +-# +-# Verify data after the test has been "shot" +- +-# 64 is CURLE_USE_SSL_FAILED +- +-64 +- +- +-A001 CAPABILITY +- +- +- +diff --git a/tests/data/test985 b/tests/data/test985 +deleted file mode 100644 +index d0db4aa..0000000 +--- a/tests/data/test985 ++++ /dev/null +@@ -1,54 +0,0 @@ +- +- +- +-POP3 +-STARTTLS +- +- +- +-# +-# Server-side +- +- +-REPLY CAPA -ERR Not implemented +- +- +-From: me@somewhere +-To: fake@nowhere +- +-body +- +--- +- yours sincerely +- +- +- +-# +-# Client-side +- +- +-SSL +- +- +-pop3 +- +- +-POP3 require STARTTLS with failing capabilities +- +- +-pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u user:secret --ssl-reqd +- +- +- +-# +-# Verify data after the test has been "shot" +- +-# 64 is CURLE_USE_SSL_FAILED +- +-64 +- +- +-CAPA +- +- +- +diff --git a/tests/data/test986 b/tests/data/test986 +deleted file mode 100644 +index a709437..0000000 +--- a/tests/data/test986 ++++ /dev/null +@@ -1,53 +0,0 @@ +- +- +- +-FTP +-STARTTLS +- +- +- +-# +-# Server-side +- +- +-REPLY welcome 230 Welcome +-REPLY AUTH 500 unknown command +- +- +- +-# Client-side +- +- +-SSL +- +- +-ftp +- +- +-FTP require STARTTLS while preauthenticated +- +- +-data +- to +- see +-that FTPS +-works +- so does it? +- +- +---ssl-reqd --ftp-ssl-control ftp://%HOSTIP:%FTPPORT/%TESTNUMBER -T log/test%TESTNUMBER.txt -u user:secret +- +- +- +-# Verify data after the test has been "shot" +- +-# 64 is CURLE_USE_SSL_FAILED +- +-64 +- +- +-AUTH SSL +-AUTH TLS +- +- +- diff --git a/debian/patches/0011-CVE-2022-43552-HTTP-Proxy-deny-use-after-free.patch b/debian/patches/0011-CVE-2022-43552-HTTP-Proxy-deny-use-after-free.patch new file mode 100644 index 0000000000000000000000000000000000000000..7257b016256afb9be00d0a7df4d7314f3fe3f1ec --- /dev/null +++ b/debian/patches/0011-CVE-2022-43552-HTTP-Proxy-deny-use-after-free.patch @@ -0,0 +1,3415 @@ +From: liwenjie +Date: Wed, 11 Jan 2023 15:53:58 +0800 +Subject: =?utf-8?b?Q1ZFLTIwMjItNDM1NTIg5a6J5YWo5pu05pawOkhUVFAgUHJveHkgZGVu?= + =?utf-8?b?eSB1c2UtYWZ0ZXItZnJlZS4=?= + +--- + docs/cmdline-opts/ftp-skip-pasv-ip.d | 2 + + docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 | 8 +- + lib/conncache.c | 8 +- + lib/connect.c | 20 +-- + lib/content_encoding.c | 9 ++ + lib/cookie.c | 29 ++++ + lib/easy.c | 3 +- + lib/ftp.c | 227 ++++++++++++++------------- + lib/http.c | 34 ++-- + lib/imap.c | 28 ++-- + lib/krb5.c | 5 +- + lib/multi.c | 5 +- + lib/pop3.c | 37 +++-- + lib/setopt.c | 30 ++-- + lib/smb.c | 14 +- + lib/smtp.c | 4 + + lib/strcase.c | 10 ++ + lib/strcase.h | 2 + + lib/telnet.c | 19 ++- + lib/transfer.c | 70 ++++++++- + lib/url.c | 60 +++++-- + lib/urldata.h | 40 +++-- + lib/vssh/ssh.h | 4 +- + lib/vtls/bearssl.c | 9 +- + lib/vtls/gtls.c | 51 +++--- + lib/vtls/mbedtls.c | 8 +- + lib/vtls/mesalink.c | 9 +- + lib/vtls/nss.c | 18 ++- + lib/vtls/openssl.c | 176 ++++++++++++++------- + lib/vtls/schannel.c | 10 +- + lib/vtls/sectransp.c | 9 +- + lib/vtls/vtls.c | 53 ++++++- + lib/vtls/vtls.h | 2 + + lib/vtls/wolfssl.c | 8 +- + src/tool_cb_hdr.c | 22 +-- + src/tool_cfgable.c | 1 + + src/tool_getparam.c | 5 + + tests/data/Makefile.inc | 7 +- + tests/data/test1168 | 78 +++++++++ + tests/data/test1400 | 1 + + tests/data/test1401 | 1 + + tests/data/test1402 | 1 + + tests/data/test1403 | 1 + + tests/data/test1404 | 1 + + tests/data/test1405 | 1 + + tests/data/test1406 | 1 + + tests/data/test1407 | 1 + + tests/data/test1420 | 1 + + tests/data/test973 | 88 +++++++++++ + tests/data/test974 | 87 ++++++++++ + tests/data/test975 | 88 +++++++++++ + tests/data/test976 | 88 +++++++++++ + tests/data/test980 | 52 ++++++ + tests/data/test981 | 59 +++++++ + tests/data/test982 | 57 +++++++ + tests/data/test983 | 52 ++++++ + tests/data/test984 | 56 +++++++ + tests/data/test985 | 54 +++++++ + tests/data/test986 | 53 +++++++ + 59 files changed, 1504 insertions(+), 373 deletions(-) + create mode 100644 tests/data/test1168 + create mode 100644 tests/data/test973 + create mode 100644 tests/data/test974 + create mode 100644 tests/data/test975 + create mode 100644 tests/data/test976 + create mode 100644 tests/data/test980 + create mode 100644 tests/data/test981 + create mode 100644 tests/data/test982 + create mode 100644 tests/data/test983 + create mode 100644 tests/data/test984 + create mode 100644 tests/data/test985 + create mode 100644 tests/data/test986 + +diff --git a/docs/cmdline-opts/ftp-skip-pasv-ip.d b/docs/cmdline-opts/ftp-skip-pasv-ip.d +index da6ab11..4be8b43 100644 +--- a/docs/cmdline-opts/ftp-skip-pasv-ip.d ++++ b/docs/cmdline-opts/ftp-skip-pasv-ip.d +@@ -9,4 +9,6 @@ to curl's PASV command when curl connects the data connection. Instead curl + will re-use the same IP address it already uses for the control + connection. + ++Since curl 7.74.0 this option is enabled by default. ++ + This option has no effect if PORT, EPRT or EPSV is used instead of PASV. +diff --git a/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 b/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 +index 5f234b4..d75204a 100644 +--- a/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 ++++ b/docs/libcurl/opts/CURLOPT_FTP_SKIP_PASV_IP.3 +@@ -5,7 +5,7 @@ + .\" * | (__| |_| | _ <| |___ + .\" * \___|\___/|_| \_\_____| + .\" * +-.\" * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. ++.\" * Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. + .\" * + .\" * This software is licensed as described in the file COPYING, which + .\" * you should have received as part of this distribution. The terms +@@ -36,11 +36,13 @@ address it already uses for the control connection. But it will use the port + number from the 227-response. + + This option thus allows libcurl to work around broken server installations +-that due to NATs, firewalls or incompetence report the wrong IP address back. ++that due to NATs, firewalls or incompetence report the wrong IP address ++back. Setting the option also reduces the risk for various sorts of client ++abuse by malicious servers. + + This option has no effect if PORT, EPRT or EPSV is used instead of PASV. + .SH DEFAULT +-0 ++1 since 7.74.0, was 0 before then. + .SH PROTOCOLS + FTP + .SH EXAMPLE +diff --git a/lib/conncache.c b/lib/conncache.c +index 2804464..42b0ed2 100644 +--- a/lib/conncache.c ++++ b/lib/conncache.c +@@ -158,8 +158,12 @@ static void hashkey(struct connectdata *conn, char *buf, + /* report back which name we used */ + *hostp = hostname; + +- /* put the number first so that the hostname gets cut off if too long */ +- msnprintf(buf, len, "%ld%s", port, hostname); ++ /* put the numbers first so that the hostname gets cut off if too long */ ++#ifdef ENABLE_IPV6 ++ msnprintf(buf, len, "%u/%ld/%s", conn->scope_id, port, hostname); ++#else ++ msnprintf(buf, len, "%ld/%s", port, hostname); ++#endif + } + + void Curl_conncache_unlock(struct Curl_easy *data) +diff --git a/lib/connect.c b/lib/connect.c +index 611d6d2..050acb7 100644 +--- a/lib/connect.c ++++ b/lib/connect.c +@@ -624,6 +624,7 @@ void Curl_persistconninfo(struct connectdata *conn) + conn->data->info.conn_scheme = conn->handler->scheme; + conn->data->info.conn_protocol = conn->handler->protocol; + conn->data->info.conn_primary_port = conn->primary_port; ++ conn->data->info.conn_remote_port = conn->remote_port; + conn->data->info.conn_local_port = conn->local_port; + } + +@@ -1336,15 +1337,15 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ + } + + struct connfind { +- struct connectdata *tofind; +- bool found; ++ long id_tofind; ++ struct connectdata *found; + }; + + static int conn_is_conn(struct connectdata *conn, void *param) + { + struct connfind *f = (struct connfind *)param; +- if(conn == f->tofind) { +- f->found = TRUE; ++ if(conn->connection_id == f->id_tofind) { ++ f->found = conn; + return 1; + } + return 0; +@@ -1366,21 +1367,22 @@ curl_socket_t Curl_getconnectinfo(struct Curl_easy *data, + * - that is associated with a multi handle, and whose connection + * was detached with CURLOPT_CONNECT_ONLY + */ +- if(data->state.lastconnect && (data->multi_easy || data->multi)) { +- struct connectdata *c = data->state.lastconnect; ++ if((data->state.lastconnect_id != -1) && (data->multi_easy || data->multi)) { ++ struct connectdata *c; + struct connfind find; +- find.tofind = data->state.lastconnect; +- find.found = FALSE; ++ find.id_tofind = data->state.lastconnect_id; ++ find.found = NULL; + + Curl_conncache_foreach(data, data->multi_easy? + &data->multi_easy->conn_cache: + &data->multi->conn_cache, &find, conn_is_conn); + + if(!find.found) { +- data->state.lastconnect = NULL; ++ data->state.lastconnect_id = -1; + return CURL_SOCKET_BAD; + } + ++ c = find.found; + if(connp) { + /* only store this if the caller cares for it */ + *connp = c; +diff --git a/lib/content_encoding.c b/lib/content_encoding.c +index 6d47537..e646f31 100644 +--- a/lib/content_encoding.c ++++ b/lib/content_encoding.c +@@ -934,6 +934,9 @@ static const content_encoding *find_encoding(const char *name, size_t len) + return NULL; + } + ++/* allow no more than 5 "chained" compression steps */ ++#define MAX_ENCODE_STACK 5 ++ + /* Set-up the unencoding stack from the Content-Encoding header value. + * See RFC 7231 section 3.1.2.2. */ + CURLcode Curl_build_unencoding_stack(struct connectdata *conn, +@@ -941,6 +944,7 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn, + { + struct Curl_easy *data = conn->data; + struct SingleRequest *k = &data->req; ++ int counter = 0; + + do { + const char *name; +@@ -975,6 +979,11 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn, + if(!encoding) + encoding = &error_encoding; /* Defer error at stack use. */ + ++ if(++counter >= MAX_ENCODE_STACK) { ++ failf(data, "Reject response due to %u content encodings", ++ counter); ++ return CURLE_BAD_CONTENT_ENCODING; ++ } + /* Stack the unencoding stage. */ + writer = new_unencoding_writer(conn, encoding, k->writer_stack); + if(!writer) +diff --git a/lib/cookie.c b/lib/cookie.c +index 0091132..76b6206 100644 +--- a/lib/cookie.c ++++ b/lib/cookie.c +@@ -411,6 +411,30 @@ static bool bad_domain(const char *domain) + return !strchr(domain, '.') && !strcasecompare(domain, "localhost"); + } + ++/* ++ RFC 6265 section 4.1.1 says a server should accept this range: ++ ++ cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E ++ ++ But Firefox and Chrome as of June 2022 accept space, comma and double-quotes ++ fine. The prime reason for filtering out control bytes is that some HTTP ++ servers return 400 for requests that contain such. ++*/ ++static int invalid_octets(const char *p) ++{ ++ /* Reject all bytes \x01 - \x1f (*except* \x09, TAB) + \x7f */ ++ static const char badoctets[] = { ++ "\x01\x02\x03\x04\x05\x06\x07\x08\x0a" ++ "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" ++ "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f" ++ }; ++ size_t vlen, len; ++ /* scan for all the octets that are *not* in cookie-octet */ ++ len = strcspn(p, badoctets); ++ vlen = strlen(p); ++ return (len != vlen); ++} ++ + /**************************************************************************** + * + * Curl_cookie_add() +@@ -557,6 +581,11 @@ Curl_cookie_add(struct Curl_easy *data, + badcookie = TRUE; + break; + } ++ if(invalid_octets(whatptr) || invalid_octets(name)) { ++ infof(data, "invalid octets in name/value, cookie dropped"); ++ badcookie = TRUE; ++ break; ++ } + } + else if(!len) { + /* this was a "=" with no content, and we must allow +diff --git a/lib/easy.c b/lib/easy.c +index 6382cee..3b4c778 100644 +--- a/lib/easy.c ++++ b/lib/easy.c +@@ -832,8 +832,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data) + + /* the connection cache is setup on demand */ + outcurl->state.conn_cache = NULL; +- +- outcurl->state.lastconnect = NULL; ++ outcurl->state.lastconnect_id = -1; + + outcurl->progress.flags = data->progress.flags; + outcurl->progress.callback = data->progress.callback; +diff --git a/lib/ftp.c b/lib/ftp.c +index 469096f..688c11e 100644 +--- a/lib/ftp.c ++++ b/lib/ftp.c +@@ -2497,7 +2497,7 @@ static CURLcode ftp_state_loggedin(struct connectdata *conn) + { + CURLcode result = CURLE_OK; + +- if(conn->ssl[FIRSTSOCKET].use) { ++ if(conn->bits.ftp_use_control_ssl) { + /* PBSZ = PROTECTION BUFFER SIZE. + + The 'draft-murray-auth-ftp-ssl' (draft 12, page 7) says: +@@ -2616,9 +2616,12 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + /* we have now received a full FTP server response */ + switch(ftpc->state) { + case FTP_WAIT220: +- if(ftpcode == 230) +- /* 230 User logged in - already! */ +- return ftp_state_user_resp(conn, ftpcode, ftpc->state); ++ if(ftpcode == 230) { ++ /* 230 User logged in - already! Take as 220 if TLS required. */ ++ if(data->set.use_ssl <= CURLUSESSL_TRY || ++ conn->bits.ftp_use_control_ssl) ++ return ftp_state_user_resp(conn, ftpcode, ftpc->state); ++ } + else if(ftpcode != 220) { + failf(data, "Got a %03d ftp-server response when 220 was expected", + ftpcode); +@@ -2643,11 +2646,8 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + } + #endif + +- if(data->set.use_ssl && +- (!conn->ssl[FIRSTSOCKET].use || +- (conn->bits.proxy_ssl_connected[FIRSTSOCKET] && +- !conn->proxy_ssl[FIRSTSOCKET].use))) { +- /* We don't have a SSL/TLS connection yet, but FTPS is ++ if(data->set.use_ssl && !conn->bits.ftp_use_control_ssl) { ++ /* We don't have a SSL/TLS control connection yet, but FTPS is + requested. Try a FTPS connection now */ + + ftpc->count3 = 0; +@@ -2680,6 +2680,9 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + case FTP_AUTH: + /* we have gotten the response to a previous AUTH command */ + ++ if(pp->cache_size) ++ return CURLE_WEIRD_SERVER_REPLY; /* Forbid pipelining in response. */ ++ + /* RFC2228 (page 5) says: + * + * If the server is willing to accept the named security mechanism, +@@ -2692,6 +2695,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn) + result = Curl_ssl_connect(conn, FIRSTSOCKET); + if(!result) { + conn->bits.ftp_use_data_ssl = FALSE; /* clear-text data */ ++ conn->bits.ftp_use_control_ssl = TRUE; /* SSL on control */ + result = ftp_state_user(conn); + } + } +@@ -3082,7 +3086,7 @@ static CURLcode ftp_block_statemach(struct connectdata *conn) + * + */ + static CURLcode ftp_connect(struct connectdata *conn, +- bool *done) /* see description above */ ++ bool *done) /* see description above */ + { + CURLcode result; + struct ftp_conn *ftpc = &conn->proto.ftpc; +@@ -3103,6 +3107,7 @@ static CURLcode ftp_connect(struct connectdata *conn, + result = Curl_ssl_connect(conn, FIRSTSOCKET); + if(result) + return result; ++ conn->bits.ftp_use_control_ssl = TRUE; + } + + Curl_pp_init(pp); /* init the generic pingpong data */ +@@ -3773,129 +3778,131 @@ static CURLcode init_wc_data(struct connectdata *conn) + return result; + } + +-/* This is called recursively */ + static CURLcode wc_statemach(struct connectdata *conn) + { + struct WildcardData * const wildcard = &(conn->data->wildcard); + CURLcode result = CURLE_OK; + +- switch(wildcard->state) { +- case CURLWC_INIT: +- result = init_wc_data(conn); +- if(wildcard->state == CURLWC_CLEAN) +- /* only listing! */ +- break; +- wildcard->state = result ? CURLWC_ERROR : CURLWC_MATCHING; +- break; ++ for(;;) { ++ switch(wildcard->state) { ++ case CURLWC_INIT: ++ result = init_wc_data(conn); ++ if(wildcard->state == CURLWC_CLEAN) ++ /* only listing! */ ++ return result; ++ wildcard->state = result ? CURLWC_ERROR : CURLWC_MATCHING; ++ return result; + +- case CURLWC_MATCHING: { +- /* In this state is LIST response successfully parsed, so lets restore +- previous WRITEFUNCTION callback and WRITEDATA pointer */ +- struct ftp_wc *ftpwc = wildcard->protdata; +- conn->data->set.fwrite_func = ftpwc->backup.write_function; +- conn->data->set.out = ftpwc->backup.file_descriptor; +- ftpwc->backup.write_function = ZERO_NULL; +- ftpwc->backup.file_descriptor = NULL; +- wildcard->state = CURLWC_DOWNLOADING; +- +- if(Curl_ftp_parselist_geterror(ftpwc->parser)) { +- /* error found in LIST parsing */ +- wildcard->state = CURLWC_CLEAN; +- return wc_statemach(conn); +- } +- if(wildcard->filelist.size == 0) { +- /* no corresponding file */ +- wildcard->state = CURLWC_CLEAN; +- return CURLE_REMOTE_FILE_NOT_FOUND; ++ case CURLWC_MATCHING: { ++ /* In this state is LIST response successfully parsed, so lets restore ++ previous WRITEFUNCTION callback and WRITEDATA pointer */ ++ struct ftp_wc *ftpwc = wildcard->protdata; ++ conn->data->set.fwrite_func = ftpwc->backup.write_function; ++ conn->data->set.out = ftpwc->backup.file_descriptor; ++ ftpwc->backup.write_function = ZERO_NULL; ++ ftpwc->backup.file_descriptor = NULL; ++ wildcard->state = CURLWC_DOWNLOADING; ++ ++ if(Curl_ftp_parselist_geterror(ftpwc->parser)) { ++ /* error found in LIST parsing */ ++ wildcard->state = CURLWC_CLEAN; ++ continue; ++ } ++ if(wildcard->filelist.size == 0) { ++ /* no corresponding file */ ++ wildcard->state = CURLWC_CLEAN; ++ return CURLE_REMOTE_FILE_NOT_FOUND; ++ } ++ continue; + } +- return wc_statemach(conn); +- } + +- case CURLWC_DOWNLOADING: { +- /* filelist has at least one file, lets get first one */ +- struct ftp_conn *ftpc = &conn->proto.ftpc; +- struct curl_fileinfo *finfo = wildcard->filelist.head->ptr; +- struct FTP *ftp = conn->data->req.protop; ++ case CURLWC_DOWNLOADING: { ++ /* filelist has at least one file, lets get first one */ ++ struct ftp_conn *ftpc = &conn->proto.ftpc; ++ struct curl_fileinfo *finfo = wildcard->filelist.head->ptr; ++ struct FTP *ftp = conn->data->req.protop; + +- char *tmp_path = aprintf("%s%s", wildcard->path, finfo->filename); +- if(!tmp_path) +- return CURLE_OUT_OF_MEMORY; ++ char *tmp_path = aprintf("%s%s", wildcard->path, finfo->filename); ++ if(!tmp_path) ++ return CURLE_OUT_OF_MEMORY; + +- /* switch default ftp->path and tmp_path */ +- free(ftp->pathalloc); +- ftp->pathalloc = ftp->path = tmp_path; +- +- infof(conn->data, "Wildcard - START of \"%s\"\n", finfo->filename); +- if(conn->data->set.chunk_bgn) { +- long userresponse; +- Curl_set_in_callback(conn->data, true); +- userresponse = conn->data->set.chunk_bgn( +- finfo, wildcard->customptr, (int)wildcard->filelist.size); +- Curl_set_in_callback(conn->data, false); +- switch(userresponse) { +- case CURL_CHUNK_BGN_FUNC_SKIP: +- infof(conn->data, "Wildcard - \"%s\" skipped by user\n", +- finfo->filename); +- wildcard->state = CURLWC_SKIP; +- return wc_statemach(conn); +- case CURL_CHUNK_BGN_FUNC_FAIL: +- return CURLE_CHUNK_FAILED; ++ /* switch default ftp->path and tmp_path */ ++ free(ftp->pathalloc); ++ ftp->pathalloc = ftp->path = tmp_path; ++ ++ infof(conn->data, "Wildcard - START of \"%s\"\n", finfo->filename); ++ if(conn->data->set.chunk_bgn) { ++ long userresponse; ++ Curl_set_in_callback(conn->data, true); ++ userresponse = conn->data->set.chunk_bgn( ++ finfo, wildcard->customptr, (int)wildcard->filelist.size); ++ Curl_set_in_callback(conn->data, false); ++ switch(userresponse) { ++ case CURL_CHUNK_BGN_FUNC_SKIP: ++ infof(conn->data, "Wildcard - \"%s\" skipped by user\n", ++ finfo->filename); ++ wildcard->state = CURLWC_SKIP; ++ continue; ++ case CURL_CHUNK_BGN_FUNC_FAIL: ++ return CURLE_CHUNK_FAILED; ++ } + } +- } + +- if(finfo->filetype != CURLFILETYPE_FILE) { +- wildcard->state = CURLWC_SKIP; +- return wc_statemach(conn); +- } ++ if(finfo->filetype != CURLFILETYPE_FILE) { ++ wildcard->state = CURLWC_SKIP; ++ continue; ++ } + +- if(finfo->flags & CURLFINFOFLAG_KNOWN_SIZE) +- ftpc->known_filesize = finfo->size; ++ if(finfo->flags & CURLFINFOFLAG_KNOWN_SIZE) ++ ftpc->known_filesize = finfo->size; + +- result = ftp_parse_url_path(conn); +- if(result) +- return result; ++ result = ftp_parse_url_path(conn); ++ if(result) ++ return result; + +- /* we don't need the Curl_fileinfo of first file anymore */ +- Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); ++ /* we don't need the Curl_fileinfo of first file anymore */ ++ Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); + +- if(wildcard->filelist.size == 0) { /* remains only one file to down. */ +- wildcard->state = CURLWC_CLEAN; +- /* after that will be ftp_do called once again and no transfer +- will be done because of CURLWC_CLEAN state */ +- return CURLE_OK; ++ if(wildcard->filelist.size == 0) { /* remains only one file to down. */ ++ wildcard->state = CURLWC_CLEAN; ++ /* after that will be ftp_do called once again and no transfer ++ will be done because of CURLWC_CLEAN state */ ++ return CURLE_OK; ++ } ++ return result; + } +- } break; + +- case CURLWC_SKIP: { +- if(conn->data->set.chunk_end) { +- Curl_set_in_callback(conn->data, true); +- conn->data->set.chunk_end(conn->data->wildcard.customptr); +- Curl_set_in_callback(conn->data, false); ++ case CURLWC_SKIP: { ++ if(conn->data->set.chunk_end) { ++ Curl_set_in_callback(conn->data, true); ++ conn->data->set.chunk_end(conn->data->wildcard.customptr); ++ Curl_set_in_callback(conn->data, false); ++ } ++ Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); ++ wildcard->state = (wildcard->filelist.size == 0) ? ++ CURLWC_CLEAN : CURLWC_DOWNLOADING; ++ continue; + } +- Curl_llist_remove(&wildcard->filelist, wildcard->filelist.head, NULL); +- wildcard->state = (wildcard->filelist.size == 0) ? +- CURLWC_CLEAN : CURLWC_DOWNLOADING; +- return wc_statemach(conn); +- } + +- case CURLWC_CLEAN: { +- struct ftp_wc *ftpwc = wildcard->protdata; +- result = CURLE_OK; +- if(ftpwc) +- result = Curl_ftp_parselist_geterror(ftpwc->parser); ++ case CURLWC_CLEAN: { ++ struct ftp_wc *ftpwc = wildcard->protdata; ++ result = CURLE_OK; ++ if(ftpwc) ++ result = Curl_ftp_parselist_geterror(ftpwc->parser); + +- wildcard->state = result ? CURLWC_ERROR : CURLWC_DONE; +- } break; ++ wildcard->state = result ? CURLWC_ERROR : CURLWC_DONE; ++ return result; ++ } + +- case CURLWC_DONE: +- case CURLWC_ERROR: +- case CURLWC_CLEAR: +- if(wildcard->dtor) +- wildcard->dtor(wildcard->protdata); +- break; ++ case CURLWC_DONE: ++ case CURLWC_ERROR: ++ case CURLWC_CLEAR: ++ if(wildcard->dtor) ++ wildcard->dtor(wildcard->protdata); ++ return result; ++ } + } +- +- return result; ++ /* UNREACHABLE */ + } + + /*********************************************************************** +diff --git a/lib/http.c b/lib/http.c +index 837f53c..4d6626b 100644 +--- a/lib/http.c ++++ b/lib/http.c +@@ -733,6 +733,21 @@ output_auth_headers(struct connectdata *conn, + return CURLE_OK; + } + ++/* ++ * allow_auth_to_host() tells if autentication, cookies or other "sensitive ++ * data" can (still) be sent to this host. ++ */ ++static bool allow_auth_to_host(struct Curl_easy *data) ++{ ++ struct connectdata *conn = data->conn; ++ return (!data->state.this_is_a_follow || ++ data->set.allow_auth_to_other_hosts || ++ (data->state.first_host && ++ strcasecompare(data->state.first_host, conn->host.name) && ++ (data->state.first_remote_port == conn->remote_port) && ++ (data->state.first_remote_protocol == conn->handler->protocol))); ++} ++ + /** + * Curl_http_output_auth() setups the authentication headers for the + * host/proxy and the correct authentication +@@ -801,15 +816,12 @@ Curl_http_output_auth(struct connectdata *conn, + with it */ + authproxy->done = TRUE; + +- /* To prevent the user+password to get sent to other than the original +- host due to a location-follow, we do some weirdo checks here */ +- if(!data->state.this_is_a_follow || +- conn->bits.netrc || +- !data->state.first_host || +- data->set.allow_auth_to_other_hosts || +- strcasecompare(data->state.first_host, conn->host.name)) { ++ /* To prevent the user+password to get sent to other than the original host ++ due to a location-follow */ ++ if(allow_auth_to_host(data) ++ || conn->bits.netrc ++ ) + result = output_auth_headers(conn, authhost, request, path, FALSE); +- } + else + authhost->done = TRUE; + +@@ -1881,10 +1893,7 @@ CURLcode Curl_add_custom_headers(struct connectdata *conn, + checkprefix("Cookie:", compare)) && + /* be careful of sending this potentially sensitive header to + other hosts */ +- (data->state.this_is_a_follow && +- data->state.first_host && +- !data->set.allow_auth_to_other_hosts && +- !strcasecompare(data->state.first_host, conn->host.name))) ++ !allow_auth_to_host(data)) + ; + else { + result = Curl_add_bufferf(&req_buffer, "%s\r\n", compare); +@@ -2067,6 +2076,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) + return CURLE_OUT_OF_MEMORY; + + data->state.first_remote_port = conn->remote_port; ++ data->state.first_remote_protocol = conn->handler->protocol; + } + + if((conn->handler->protocol&(PROTO_FAMILY_HTTP|CURLPROTO_FTP)) && +diff --git a/lib/imap.c b/lib/imap.c +index 66172bd..0ca700f 100644 +--- a/lib/imap.c ++++ b/lib/imap.c +@@ -917,22 +917,18 @@ static CURLcode imap_state_capability_resp(struct connectdata *conn, + line += wordlen; + } + } +- else if(imapcode == IMAP_RESP_OK) { +- if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { +- /* We don't have a SSL/TLS connection yet, but SSL is requested */ +- if(imapc->tls_supported) +- /* Switch to TLS connection now */ +- result = imap_perform_starttls(conn); +- else if(data->set.use_ssl == CURLUSESSL_TRY) +- /* Fallback and carry on with authentication */ +- result = imap_perform_authentication(conn); +- else { +- failf(data, "STARTTLS not supported."); +- result = CURLE_USE_SSL_FAILED; +- } ++ else if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { ++ /* PREAUTH is not compatible with STARTTLS. */ ++ if(imapcode == IMAP_RESP_OK && imapc->tls_supported && !imapc->preauth) { ++ /* Switch to TLS connection now */ ++ result = imap_perform_starttls(conn); + } +- else ++ else if(data->set.use_ssl <= CURLUSESSL_TRY) + result = imap_perform_authentication(conn); ++ else { ++ failf(data, "STARTTLS not available."); ++ result = CURLE_USE_SSL_FAILED; ++ } + } + else + result = imap_perform_authentication(conn); +@@ -950,6 +946,10 @@ static CURLcode imap_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + ++ /* Pipelining in response is forbidden. */ ++ if(data->conn->proto.imapc.pp.cache_size) ++ return CURLE_WEIRD_SERVER_REPLY; ++ + if(imapcode != IMAP_RESP_OK) { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied"); +diff --git a/lib/krb5.c b/lib/krb5.c +index f50287a..5b77e35 100644 +--- a/lib/krb5.c ++++ b/lib/krb5.c +@@ -86,11 +86,8 @@ krb5_decode(void *app_data, void *buf, int len, + enc.value = buf; + enc.length = len; + maj = gss_unwrap(&min, *context, &enc, &dec, NULL, NULL); +- if(maj != GSS_S_COMPLETE) { +- if(len >= 4) +- strcpy(buf, "599 "); ++ if(maj != GSS_S_COMPLETE) + return -1; +- } + + memcpy(buf, dec.value, dec.length); + len = curlx_uztosi(dec.length); +diff --git a/lib/multi.c b/lib/multi.c +index 6d819b4..a1d25b6 100644 +--- a/lib/multi.c ++++ b/lib/multi.c +@@ -451,6 +451,7 @@ CURLMcode curl_multi_add_handle(struct Curl_multi *multi, + data->state.conn_cache = &data->share->conn_cache; + else + data->state.conn_cache = &multi->conn_cache; ++ data->state.lastconnect_id = -1; + + #ifdef USE_LIBPSL + /* Do the same for PSL. */ +@@ -663,11 +664,11 @@ static CURLcode multi_done(struct Curl_easy *data, + CONN_UNLOCK(data); + if(Curl_conncache_return_conn(data, conn)) { + /* remember the most recently used connection */ +- data->state.lastconnect = conn; ++ data->state.lastconnect_id = conn->connection_id; + infof(data, "%s\n", buffer); + } + else +- data->state.lastconnect = NULL; ++ data->state.lastconnect_id = -1; + } + + Curl_free_request_state(data); +diff --git a/lib/pop3.c b/lib/pop3.c +index 57c1373..8a2d52e 100644 +--- a/lib/pop3.c ++++ b/lib/pop3.c +@@ -721,28 +721,23 @@ static CURLcode pop3_state_capa_resp(struct connectdata *conn, int pop3code, + } + } + } +- else if(pop3code == '+') { +- if(data->set.use_ssl && !conn->ssl[FIRSTSOCKET].use) { +- /* We don't have a SSL/TLS connection yet, but SSL is requested */ +- if(pop3c->tls_supported) +- /* Switch to TLS connection now */ +- result = pop3_perform_starttls(conn); +- else if(data->set.use_ssl == CURLUSESSL_TRY) +- /* Fallback and carry on with authentication */ +- result = pop3_perform_authentication(conn); +- else { +- failf(data, "STLS not supported."); +- result = CURLE_USE_SSL_FAILED; +- } +- } +- else +- result = pop3_perform_authentication(conn); +- } + else { + /* Clear text is supported when CAPA isn't recognised */ +- pop3c->authtypes |= POP3_TYPE_CLEARTEXT; ++ if(pop3code != '+') ++ pop3c->authtypes |= POP3_TYPE_CLEARTEXT; + +- result = pop3_perform_authentication(conn); ++ if(!data->set.use_ssl || conn->ssl[FIRSTSOCKET].use) ++ result = pop3_perform_authentication(conn); ++ else if(pop3code == '+' && pop3c->tls_supported) ++ /* Switch to TLS connection now */ ++ result = pop3_perform_starttls(conn); ++ else if(data->set.use_ssl <= CURLUSESSL_TRY) ++ /* Fallback and carry on with authentication */ ++ result = pop3_perform_authentication(conn); ++ else { ++ failf(data, "STLS not supported."); ++ result = CURLE_USE_SSL_FAILED; ++ } + } + + return result; +@@ -758,6 +753,10 @@ static CURLcode pop3_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + ++ /* Pipelining in response is forbidden. */ ++ if(data->conn->proto.pop3c.pp.cache_size) ++ return CURLE_WEIRD_SERVER_REPLY; ++ + if(pop3code != '+') { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied"); +diff --git a/lib/setopt.c b/lib/setopt.c +index 5f88ad3..60bdb27 100644 +--- a/lib/setopt.c ++++ b/lib/setopt.c +@@ -486,6 +486,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + } + else + data->set.httpreq = HTTPREQ_GET; ++ data->set.upload = FALSE; + break; + + case CURLOPT_COPYPOSTFIELDS: +@@ -2130,6 +2131,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + + case CURLOPT_SSL_OPTIONS: + arg = va_arg(param, long); ++ data->set.ssl.primary.ssl_options = (unsigned char)(arg & 0xff); + data->set.ssl.enable_beast = + (bool)((arg&CURLSSLOPT_ALLOW_BEAST) ? TRUE : FALSE); + data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE); +@@ -2139,6 +2141,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + #ifndef CURL_DISABLE_PROXY + case CURLOPT_PROXY_SSL_OPTIONS: + arg = va_arg(param, long); ++ data->set.proxy_ssl.primary.ssl_options = (unsigned char)(arg & 0xff); + data->set.proxy_ssl.enable_beast = + (bool)((arg&CURLSSLOPT_ALLOW_BEAST) ? TRUE : FALSE); + data->set.proxy_ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE); +@@ -2537,44 +2540,47 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param) + case CURLOPT_TLSAUTH_USERNAME: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_ORIG], + va_arg(param, char *)); +- if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype) +- data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && ++ !data->set.ssl.primary.authtype) ++ data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ + break; + case CURLOPT_PROXY_TLSAUTH_USERNAME: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_PROXY], + va_arg(param, char *)); + if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] && +- !data->set.proxy_ssl.authtype) +- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ !data->set.proxy_ssl.primary.authtype) ++ data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default to ++ SRP */ + break; + case CURLOPT_TLSAUTH_PASSWORD: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_ORIG], + va_arg(param, char *)); +- if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && !data->set.ssl.authtype) +- data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ if(data->set.str[STRING_TLSAUTH_USERNAME_ORIG] && ++ !data->set.ssl.primary.authtype) ++ data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default */ + break; + case CURLOPT_PROXY_TLSAUTH_PASSWORD: + result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_PROXY], + va_arg(param, char *)); + if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] && +- !data->set.proxy_ssl.authtype) +- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ ++ !data->set.proxy_ssl.primary.authtype) ++ data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default */ + break; + case CURLOPT_TLSAUTH_TYPE: + argptr = va_arg(param, char *); + if(!argptr || + strncasecompare(argptr, "SRP", strlen("SRP"))) +- data->set.ssl.authtype = CURL_TLSAUTH_SRP; ++ data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; + else +- data->set.ssl.authtype = CURL_TLSAUTH_NONE; ++ data->set.ssl.primary.authtype = CURL_TLSAUTH_NONE; + break; + case CURLOPT_PROXY_TLSAUTH_TYPE: + argptr = va_arg(param, char *); + if(!argptr || + strncasecompare(argptr, "SRP", strlen("SRP"))) +- data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; ++ data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; + else +- data->set.proxy_ssl.authtype = CURL_TLSAUTH_NONE; ++ data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_NONE; + break; + #endif + #ifdef USE_ARES +diff --git a/lib/smb.c b/lib/smb.c +index 12f9925..8db3b27 100644 +--- a/lib/smb.c ++++ b/lib/smb.c +@@ -61,8 +61,6 @@ static CURLcode smb_connect(struct connectdata *conn, bool *done); + static CURLcode smb_connection_state(struct connectdata *conn, bool *done); + static CURLcode smb_do(struct connectdata *conn, bool *done); + static CURLcode smb_request_state(struct connectdata *conn, bool *done); +-static CURLcode smb_done(struct connectdata *conn, CURLcode status, +- bool premature); + static CURLcode smb_disconnect(struct connectdata *conn, bool dead); + static int smb_getsock(struct connectdata *conn, curl_socket_t *socks); + static CURLcode smb_parse_url_path(struct connectdata *conn); +@@ -74,7 +72,7 @@ const struct Curl_handler Curl_handler_smb = { + "SMB", /* scheme */ + smb_setup_connection, /* setup_connection */ + smb_do, /* do_it */ +- smb_done, /* done */ ++ ZERO_NULL, /* done */ + ZERO_NULL, /* do_more */ + smb_connect, /* connect_it */ + smb_connection_state, /* connecting */ +@@ -99,7 +97,7 @@ const struct Curl_handler Curl_handler_smbs = { + "SMBS", /* scheme */ + smb_setup_connection, /* setup_connection */ + smb_do, /* do_it */ +- smb_done, /* done */ ++ ZERO_NULL, /* done */ + ZERO_NULL, /* do_more */ + smb_connect, /* connect_it */ + smb_connection_state, /* connecting */ +@@ -919,14 +917,6 @@ static CURLcode smb_request_state(struct connectdata *conn, bool *done) + return CURLE_OK; + } + +-static CURLcode smb_done(struct connectdata *conn, CURLcode status, +- bool premature) +-{ +- (void) premature; +- Curl_safefree(conn->data->req.protop); +- return status; +-} +- + static CURLcode smb_disconnect(struct connectdata *conn, bool dead) + { + struct smb_conn *smbc = &conn->proto.smbc; +diff --git a/lib/smtp.c b/lib/smtp.c +index 65220b0..718b289 100644 +--- a/lib/smtp.c ++++ b/lib/smtp.c +@@ -680,6 +680,10 @@ static CURLcode smtp_state_starttls_resp(struct connectdata *conn, + + (void)instate; /* no use for this yet */ + ++ /* Pipelining in response is forbidden. */ ++ if(data->conn->proto.smtpc.pp.cache_size) ++ return CURLE_WEIRD_SERVER_REPLY; ++ + if(smtpcode != 220) { + if(data->set.use_ssl != CURLUSESSL_TRY) { + failf(data, "STARTTLS denied, code %d", smtpcode); +diff --git a/lib/strcase.c b/lib/strcase.c +index a894712..68e2773 100644 +--- a/lib/strcase.c ++++ b/lib/strcase.c +@@ -249,6 +249,16 @@ void Curl_strntolower(char *dest, const char *src, size_t n) + } while(*src++ && --n); + } + ++/* Compare case-sensitive NUL-terminated strings, taking care of possible ++ * null pointers. Return true if arguments match. ++ */ ++bool Curl_safecmp(char *a, char *b) ++{ ++ if(a && b) ++ return !strcmp(a, b); ++ return !a && !b; ++} ++ + /* --- public functions --- */ + + int curl_strequal(const char *first, const char *second) +diff --git a/lib/strcase.h b/lib/strcase.h +index baa768b..3665d5a 100644 +--- a/lib/strcase.h ++++ b/lib/strcase.h +@@ -49,4 +49,6 @@ char Curl_raw_tolower(char in); + void Curl_strntoupper(char *dest, const char *src, size_t n); + void Curl_strntolower(char *dest, const char *src, size_t n); + ++bool Curl_safecmp(char *a, char *b); ++ + #endif /* HEADER_CURL_STRCASE_H */ +diff --git a/lib/telnet.c b/lib/telnet.c +index 4bf4c65..f585bce 100644 +--- a/lib/telnet.c ++++ b/lib/telnet.c +@@ -967,12 +967,17 @@ static void suboption(struct connectdata *conn) + size_t tmplen = (strlen(v->data) + 1); + /* Add the variable only if it fits */ + if(len + tmplen < (int)sizeof(temp)-6) { +- if(sscanf(v->data, "%127[^,],%127s", varname, varval)) { +- msnprintf((char *)&temp[len], sizeof(temp) - len, +- "%c%s%c%s", CURL_NEW_ENV_VAR, varname, +- CURL_NEW_ENV_VALUE, varval); +- len += tmplen; +- } ++ int rv; ++ char sep[2] = ""; ++ varval[0] = 0; ++ rv = sscanf(v->data, "%127[^,]%1[,]%127s", varname, sep, varval); ++ if(rv == 1) ++ len += msnprintf((char *)&temp[len], sizeof(temp) - len, ++ "%c%s", CURL_NEW_ENV_VAR, varname); ++ else if(rv >= 2) ++ len += msnprintf((char *)&temp[len], sizeof(temp) - len, ++ "%c%s%c%s", CURL_NEW_ENV_VAR, varname, ++ CURL_NEW_ENV_VALUE, varval); + } + } + msnprintf((char *)&temp[len], sizeof(temp) - len, +@@ -1290,8 +1295,6 @@ static CURLcode telnet_done(struct connectdata *conn, + curl_slist_free_all(tn->telnet_vars); + tn->telnet_vars = NULL; + +- Curl_safefree(conn->data->req.protop); +- + return CURLE_OK; + } + +diff --git a/lib/transfer.c b/lib/transfer.c +index ead8b36..f279c5b 100644 +--- a/lib/transfer.c ++++ b/lib/transfer.c +@@ -1572,6 +1572,9 @@ CURLcode Curl_follow(struct Curl_easy *data, + data->set.followlocation++; /* count location-followers */ + + if(data->set.http_auto_referer) { ++ CURLU *u; ++ char *referer; ++ + /* We are asked to automatically set the previous URL as the referer + when we get the next URL. We pick the ->url field, which may or may + not be 100% correct */ +@@ -1581,9 +1584,27 @@ CURLcode Curl_follow(struct Curl_easy *data, + data->change.referer_alloc = FALSE; + } + +- data->change.referer = strdup(data->change.url); +- if(!data->change.referer) ++ /* Make a copy of the URL without crenditals and fragment */ ++ u = curl_url(); ++ if(!u) ++ return CURLE_OUT_OF_MEMORY; ++ ++ uc = curl_url_set(u, CURLUPART_URL, data->change.url, 0); ++ if(!uc) ++ uc = curl_url_set(u, CURLUPART_FRAGMENT, NULL, 0); ++ if(!uc) ++ uc = curl_url_set(u, CURLUPART_USER, NULL, 0); ++ if(!uc) ++ uc = curl_url_set(u, CURLUPART_PASSWORD, NULL, 0); ++ if(!uc) ++ uc = curl_url_get(u, CURLUPART_URL, &referer, 0); ++ ++ curl_url_cleanup(u); ++ ++ if(uc || referer == NULL) + return CURLE_OUT_OF_MEMORY; ++ ++ data->change.referer = referer; + data->change.referer_alloc = TRUE; /* yes, free this later */ + } + } +@@ -1608,10 +1629,53 @@ CURLcode Curl_follow(struct Curl_easy *data, + return CURLE_OUT_OF_MEMORY; + } + else { +- + uc = curl_url_get(data->state.uh, CURLUPART_URL, &newurl, 0); + if(uc) + return Curl_uc_to_curlcode(uc); ++ ++ /* Clear auth if this redirects to a different port number or protocol, ++ unless permitted */ ++ if(!data->set.allow_auth_to_other_hosts && (type != FOLLOW_FAKE)) { ++ char *portnum; ++ int port; ++ bool clear = FALSE; ++ ++ uc = curl_url_get(data->state.uh, CURLUPART_PORT, &portnum, ++ CURLU_DEFAULT_PORT); ++ if(uc) { ++ free(newurl); ++ return Curl_uc_to_curlcode(uc); ++ } ++ port = atoi(portnum); ++ free(portnum); ++ ++ if(port != data->info.conn_remote_port) { ++ infof(data, "Clear auth, redirects to port from %u to %u", ++ data->info.conn_remote_port, port); ++ clear = TRUE; ++ } ++ else { ++ char *scheme; ++ const struct Curl_handler *p; ++ uc = curl_url_get(data->state.uh, CURLUPART_SCHEME, &scheme, 0); ++ if(uc) { ++ free(newurl); ++ return Curl_uc_to_curlcode(uc); ++ } ++ ++ p = Curl_builtin_scheme(scheme); ++ if(p && (p->protocol != data->info.conn_protocol)) { ++ infof(data, "Clear auth, redirects scheme from %s to %s", ++ data->info.conn_scheme, scheme); ++ clear = TRUE; ++ } ++ free(scheme); ++ } ++ if(clear) { ++ Curl_safefree(data->set.str[STRING_USERNAME]); ++ Curl_safefree(data->set.str[STRING_PASSWORD]); ++ } ++ } + } + + if(type == FOLLOW_FAKE) { +diff --git a/lib/url.c b/lib/url.c +index 56fb736..01f7eda 100644 +--- a/lib/url.c ++++ b/lib/url.c +@@ -456,6 +456,7 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) + set->ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */ + set->ftp_use_pret = FALSE; /* mainly useful for drftpd servers */ + set->ftp_filemethod = FTPFILE_MULTICWD; ++ set->ftp_skip_ip = TRUE; /* skip PASV IP by default */ + #endif + set->dns_cache_timeout = 60; /* Timeout every 60 seconds by default */ + +@@ -482,7 +483,7 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data) + set->ssl.primary.verifypeer = TRUE; + set->ssl.primary.verifyhost = TRUE; + #ifdef USE_TLS_SRP +- set->ssl.authtype = CURL_TLSAUTH_NONE; ++ set->ssl.primary.authtype = CURL_TLSAUTH_NONE; + #endif + set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth + type */ +@@ -618,7 +619,7 @@ CURLcode Curl_open(struct Curl_easy **curl) + Curl_initinfo(data); + + /* most recent connection is not yet defined */ +- data->state.lastconnect = NULL; ++ data->state.lastconnect_id = -1; + + data->progress.flags |= PGRS_HIDE; + data->state.current_speed = -1; /* init to negative == impossible */ +@@ -996,6 +997,12 @@ static void prune_dead_connections(struct Curl_easy *data) + } + } + ++static bool ssh_config_matches(struct connectdata *one, ++ struct connectdata *two) ++{ ++ return (Curl_safecmp(one->proto.sshc.rsa, two->proto.sshc.rsa) && ++ Curl_safecmp(one->proto.sshc.rsa_pub, two->proto.sshc.rsa_pub)); ++} + /* + * Given one filled in connection struct (named needle), this function should + * detect if there already is one that has all the significant details +@@ -1218,12 +1225,19 @@ ConnectionExists(struct Curl_easy *data, + /* This protocol requires credentials per connection, + so verify that we're using the same name and password as well */ + if(strcmp(needle->user, check->user) || +- strcmp(needle->passwd, check->passwd)) { ++ strcmp(needle->passwd, check->passwd) || ++ !Curl_safecmp(needle->sasl_authzid, check->sasl_authzid) || ++ !Curl_safecmp(needle->oauth_bearer, check->oauth_bearer)) { + /* one of them was different */ + continue; + } + } + ++ if(get_protocol_family(needle->handler->protocol) == PROTO_FAMILY_SSH) { ++ if(!ssh_config_matches(needle, check)) ++ continue; ++ } ++ + if(!needle->bits.httpproxy || (needle->handler->flags&PROTOPT_SSL) || + needle->bits.tunnel_proxy) { + /* The requested connection does not use a HTTP proxy or it uses SSL or +@@ -1605,10 +1619,16 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) + conn->ssl_config.verifystatus = data->set.ssl.primary.verifystatus; + conn->ssl_config.verifypeer = data->set.ssl.primary.verifypeer; + conn->ssl_config.verifyhost = data->set.ssl.primary.verifyhost; ++ conn->ssl_config.ssl_options = data->set.ssl.primary.ssl_options; ++#ifdef USE_TLS_SRP ++#endif + conn->proxy_ssl_config.verifystatus = + data->set.proxy_ssl.primary.verifystatus; + conn->proxy_ssl_config.verifypeer = data->set.proxy_ssl.primary.verifypeer; + conn->proxy_ssl_config.verifyhost = data->set.proxy_ssl.primary.verifyhost; ++ conn->proxy_ssl_config.ssl_options = data->set.proxy_ssl.primary.ssl_options; ++#ifdef USE_TLS_SRP ++#endif + conn->ip_version = data->set.ipver; + conn->bits.connect_only = data->set.connect_only; + conn->transport = TRNSPRT_TCP; /* most of them are TCP streams */ +@@ -2733,12 +2753,14 @@ static CURLcode override_login(struct Curl_easy *data, + + /* for updated strings, we update them in the URL */ + if(user_changed) { +- uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp, 0); ++ uc = curl_url_set(data->state.uh, CURLUPART_USER, *userp, ++ CURLU_URLENCODE); + if(uc) + return Curl_uc_to_curlcode(uc); + } + if(passwd_changed) { +- uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp, 0); ++ uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD, *passwdp, ++ CURLU_URLENCODE); + if(uc) + return Curl_uc_to_curlcode(uc); + } +@@ -3352,6 +3374,14 @@ static CURLcode create_conn(struct Curl_easy *data, + } + } + ++ if(data->set.str[STRING_BEARER]) { ++ conn->oauth_bearer = strdup(data->set.str[STRING_BEARER]); ++ if(!conn->oauth_bearer) { ++ result = CURLE_OUT_OF_MEMORY; ++ goto out; ++ } ++ } ++ + #ifdef USE_UNIX_SOCKETS + if(data->set.str[STRING_UNIX_SOCKET_PATH]) { + conn->unix_domain_socket = strdup(data->set.str[STRING_UNIX_SOCKET_PATH]); +@@ -3520,6 +3550,9 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.proxy_ssl.primary.CApath = data->set.str[STRING_SSL_CAPATH_PROXY]; + data->set.ssl.primary.CAfile = data->set.str[STRING_SSL_CAFILE_ORIG]; + data->set.proxy_ssl.primary.CAfile = data->set.str[STRING_SSL_CAFILE_PROXY]; ++ data->set.ssl.primary.issuercert = data->set.str[STRING_SSL_ISSUERCERT_ORIG]; ++ data->set.proxy_ssl.primary.issuercert = ++ data->set.str[STRING_SSL_ISSUERCERT_PROXY]; + data->set.ssl.primary.random_file = data->set.str[STRING_SSL_RANDOM_FILE]; + data->set.proxy_ssl.primary.random_file = + data->set.str[STRING_SSL_RANDOM_FILE]; +@@ -3538,10 +3571,9 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.proxy_ssl.primary.pinned_key = + data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY]; + +- data->set.ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_ORIG]; +- data->set.proxy_ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_PROXY]; +- data->set.ssl.issuercert = data->set.str[STRING_SSL_ISSUERCERT_ORIG]; +- data->set.proxy_ssl.issuercert = data->set.str[STRING_SSL_ISSUERCERT_PROXY]; ++ data->set.ssl.primary.CRLfile = data->set.str[STRING_SSL_CRLFILE_ORIG]; ++ data->set.proxy_ssl.primary.CRLfile = ++ data->set.str[STRING_SSL_CRLFILE_PROXY]; + data->set.ssl.cert = data->set.str[STRING_CERT_ORIG]; + data->set.proxy_ssl.cert = data->set.str[STRING_CERT_PROXY]; + data->set.ssl.cert_type = data->set.str[STRING_CERT_TYPE_ORIG]; +@@ -3555,10 +3587,12 @@ static CURLcode create_conn(struct Curl_easy *data, + data->set.ssl.primary.clientcert = data->set.str[STRING_CERT_ORIG]; + data->set.proxy_ssl.primary.clientcert = data->set.str[STRING_CERT_PROXY]; + #ifdef USE_TLS_SRP +- data->set.ssl.username = data->set.str[STRING_TLSAUTH_USERNAME_ORIG]; +- data->set.proxy_ssl.username = data->set.str[STRING_TLSAUTH_USERNAME_PROXY]; +- data->set.ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD_ORIG]; +- data->set.proxy_ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD_PROXY]; ++ data->set.ssl.primary.username = data->set.str[STRING_TLSAUTH_USERNAME_ORIG]; ++ data->set.proxy_ssl.primary.username = ++ data->set.str[STRING_TLSAUTH_USERNAME_PROXY]; ++ data->set.ssl.primary.password = data->set.str[STRING_TLSAUTH_PASSWORD_ORIG]; ++ data->set.proxy_ssl.primary.password = ++ data->set.str[STRING_TLSAUTH_PASSWORD_PROXY]; + #endif + + if(!Curl_clone_primary_ssl_config(&data->set.ssl.primary, +diff --git a/lib/urldata.h b/lib/urldata.h +index 3effb16..8f3c31d 100644 +--- a/lib/urldata.h ++++ b/lib/urldata.h +@@ -224,12 +224,20 @@ struct ssl_primary_config { + long version_max; /* max supported version the client wants to use*/ + char *CApath; /* certificate dir (doesn't work on windows) */ + char *CAfile; /* certificate to verify peer against */ ++ char *issuercert; /* optional issuer certificate filename */ + char *clientcert; + char *random_file; /* path to file containing "random" data */ + char *egdsocket; /* path to file containing the EGD daemon socket */ + char *cipher_list; /* list of ciphers to use */ + char *cipher_list13; /* list of TLS 1.3 cipher suites to use */ + char *pinned_key; ++ char *CRLfile; /* CRL to check certificate revocation */ ++#ifdef USE_TLS_SRP ++ char *username; /* TLS username (for, e.g., SRP) */ ++ char *password; /* TLS password (for, e.g., SRP) */ ++ enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */ ++#endif ++ unsigned char ssl_options; /* the CURLOPT_SSL_OPTIONS bitmask */ + BIT(verifypeer); /* set TRUE if this is desired */ + BIT(verifyhost); /* set TRUE if CN/SAN must match hostname */ + BIT(verifystatus); /* set TRUE if certificate status must be checked */ +@@ -239,8 +247,6 @@ struct ssl_primary_config { + struct ssl_config_data { + struct ssl_primary_config primary; + long certverifyresult; /* result from the certificate verification */ +- char *CRLfile; /* CRL to check certificate revocation */ +- char *issuercert;/* optional issuer certificate filename */ + curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */ + void *fsslctxp; /* parameter for call back */ + char *cert; /* client certificate file name */ +@@ -248,11 +254,6 @@ struct ssl_config_data { + char *key; /* private key file name */ + char *key_type; /* format for private key (default: PEM) */ + char *key_passwd; /* plain text private key password */ +-#ifdef USE_TLS_SRP +- char *username; /* TLS username (for, e.g., SRP) */ +- char *password; /* TLS password (for, e.g., SRP) */ +- enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */ +-#endif + BIT(certinfo); /* gather lots of certificate info */ + BIT(falsestart); + BIT(enable_beast); /* allow this flaw for interoperability's sake*/ +@@ -453,6 +454,7 @@ struct ConnectBits { + EPRT doesn't work we disable it for the forthcoming + requests */ + BIT(ftp_use_data_ssl); /* Enabled SSL for the data connection */ ++ BIT(ftp_use_control_ssl); /* Enabled SSL for the control connection */ + #endif + BIT(netrc); /* name+password provided by netrc */ + BIT(userpwd_in_url); /* name+password found in url */ +@@ -1114,7 +1116,11 @@ struct PureInfo { + reused, in the connection cache. */ + + char conn_primary_ip[MAX_IPADR_LEN]; +- long conn_primary_port; ++ int conn_primary_port; /* this is the destination port to the connection, ++ which might have been a proxy */ ++ int conn_remote_port; /* this is the "remote port", which is the port ++ number of the used URL, independent of proxy or ++ not */ + char conn_local_ip[MAX_IPADR_LEN]; + long conn_local_port; + const char *conn_scheme; +@@ -1301,7 +1307,7 @@ struct UrlState { + /* buffers to store authentication data in, as parsed from input options */ + struct curltime keeps_speed; /* for the progress meter really */ + +- struct connectdata *lastconnect; /* The last connection, NULL if undefined */ ++ long lastconnect_id; /* The last connection, -1 if undefined */ + + char *headerbuff; /* allocated buffer to store headers in */ + size_t headersize; /* size of the allocation */ +@@ -1310,13 +1316,15 @@ struct UrlState { + char *ulbuf; /* allocated upload buffer or NULL */ + curl_off_t current_speed; /* the ProgressShow() function sets this, + bytes / second */ +- char *first_host; /* host name of the first (not followed) request. +- if set, this should be the host name that we will +- sent authorization to, no else. Used to make Location: +- following not keep sending user+password... This is +- strdup() data. +- */ +- int first_remote_port; /* remote port of the first (not followed) request */ ++ ++ /* host name, port number and protocol of the first (not followed) request. ++ if set, this should be the host name that we will sent authorization to, ++ no else. Used to make Location: following not keep sending user+password. ++ This is strdup()ed data. */ ++ char *first_host; ++ int first_remote_port; ++ unsigned int first_remote_protocol; ++ + struct curl_ssl_session *session; /* array of 'max_ssl_sessions' size */ + long sessionage; /* number of the most recent session */ + unsigned int tempcount; /* number of entries in use in tempwrite, 0 - 3 */ +diff --git a/lib/vssh/ssh.h b/lib/vssh/ssh.h +index 3213c5a..e9e5a34 100644 +--- a/lib/vssh/ssh.h ++++ b/lib/vssh/ssh.h +@@ -117,8 +117,8 @@ struct ssh_conn { + + /* common */ + const char *passphrase; /* pass-phrase to use */ +- char *rsa_pub; /* path name */ +- char *rsa; /* path name */ ++ char *rsa_pub; /* strdup'ed public key file */ ++ char *rsa; /* strdup'ed private key file */ + bool authed; /* the connection has been authenticated fine */ + sshstate state; /* always use ssh.c:state() to change state! */ + sshstate nextstate; /* the state to goto after stopping */ +diff --git a/lib/vtls/bearssl.c b/lib/vtls/bearssl.c +index 67f9458..32cb0a4 100644 +--- a/lib/vtls/bearssl.c ++++ b/lib/vtls/bearssl.c +@@ -372,7 +372,8 @@ static CURLcode bearssl_connect_step1(struct connectdata *conn, int sockindex) + void *session; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &session, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &session, NULL, sockindex)) { + br_ssl_engine_set_session_parameters(&BACKEND->ctx.eng, session); + infof(data, "BearSSL: re-using session ID\n"); + } +@@ -560,10 +561,12 @@ static CURLcode bearssl_connect_step3(struct connectdata *conn, int sockindex) + return CURLE_OUT_OF_MEMORY; + br_ssl_engine_get_session_parameters(&BACKEND->ctx.eng, session); + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, &oldsession, NULL, sockindex)); ++ incache = !(Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &oldsession, NULL, sockindex)); + if(incache) + Curl_ssl_delsessionid(conn, oldsession); +- ret = Curl_ssl_addsessionid(conn, session, 0, sockindex); ++ ret = Curl_ssl_addsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ session, 0, sockindex); + Curl_ssl_sessionid_unlock(conn); + if(ret) { + free(session); +diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c +index 571e83b..92dbcd5 100644 +--- a/lib/vtls/gtls.c ++++ b/lib/vtls/gtls.c +@@ -581,8 +581,9 @@ gtls_connect_step1(struct connectdata *conn, + } + + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { +- infof(data, "Using TLS-SRP username: %s\n", SSL_SET_OPTION(username)); ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { ++ infof(data, "Using TLS-SRP username: %s\n", ++ SSL_SET_OPTION(primary.username)); + + rc = gnutls_srp_allocate_client_credentials( + &BACKEND->srp_client_cred); +@@ -593,8 +594,8 @@ gtls_connect_step1(struct connectdata *conn, + } + + rc = gnutls_srp_set_client_credentials(BACKEND->srp_client_cred, +- SSL_SET_OPTION(username), +- SSL_SET_OPTION(password)); ++ SSL_SET_OPTION(primary.username), ++ SSL_SET_OPTION(primary.password)); + if(rc != GNUTLS_E_SUCCESS) { + failf(data, "gnutls_srp_set_client_cred() failed: %s", + gnutls_strerror(rc)); +@@ -648,19 +649,19 @@ gtls_connect_step1(struct connectdata *conn, + } + #endif + +- if(SSL_SET_OPTION(CRLfile)) { ++ if(SSL_SET_OPTION(primary.CRLfile)) { + /* set the CRL list file */ + rc = gnutls_certificate_set_x509_crl_file(BACKEND->cred, +- SSL_SET_OPTION(CRLfile), ++ SSL_SET_OPTION(primary.CRLfile), + GNUTLS_X509_FMT_PEM); + if(rc < 0) { + failf(data, "error reading crl file %s (%s)", +- SSL_SET_OPTION(CRLfile), gnutls_strerror(rc)); ++ SSL_SET_OPTION(primary.CRLfile), gnutls_strerror(rc)); + return CURLE_SSL_CRL_BADFILE; + } + else + infof(data, "found %d CRL in %s\n", +- rc, SSL_SET_OPTION(CRLfile)); ++ rc, SSL_SET_OPTION(primary.CRLfile)); + } + + /* Initialize TLS session as a client */ +@@ -787,7 +788,7 @@ gtls_connect_step1(struct connectdata *conn, + #ifdef USE_TLS_SRP + /* Only add SRP to the cipher list if SRP is requested. Otherwise + * GnuTLS will disable TLS 1.3 support. */ +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { + size_t len = strlen(prioritylist); + + char *prioritysrp = malloc(len + sizeof(GNUTLS_SRP) + 1); +@@ -884,7 +885,7 @@ gtls_connect_step1(struct connectdata *conn, + + #ifdef USE_TLS_SRP + /* put the credentials to the current session */ +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) { ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP) { + rc = gnutls_credentials_set(session, GNUTLS_CRD_SRP, + BACKEND->srp_client_cred); + if(rc != GNUTLS_E_SUCCESS) { +@@ -942,7 +943,8 @@ gtls_connect_step1(struct connectdata *conn, + size_t ssl_idsize; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, &ssl_idsize, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, &ssl_idsize, sockindex)) { + /* we got a session id, use it! */ + gnutls_session_set_data(session, ssl_sessionid, ssl_idsize); + +@@ -1063,10 +1065,10 @@ gtls_connect_step3(struct connectdata *conn, + if(!chainp) { + if(SSL_CONN_CONFIG(verifypeer) || + SSL_CONN_CONFIG(verifyhost) || +- SSL_SET_OPTION(issuercert)) { ++ SSL_CONN_CONFIG(issuercert)) { + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP +- && SSL_SET_OPTION(username) != NULL ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP ++ && SSL_SET_OPTION(primary.username) != NULL + && !SSL_CONN_CONFIG(verifypeer) + && gnutls_cipher_get(session)) { + /* no peer cert, but auth is ok if we have SRP user and cipher and no +@@ -1120,7 +1122,8 @@ gtls_connect_step3(struct connectdata *conn, + failf(data, "server certificate verification failed. CAfile: %s " + "CRLfile: %s", SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile): + "none", +- SSL_SET_OPTION(CRLfile)?SSL_SET_OPTION(CRLfile):"none"); ++ SSL_SET_OPTION(primary.CRLfile) ? ++ SSL_SET_OPTION(primary.CRLfile) : "none"); + return CURLE_PEER_FAILED_VERIFICATION; + } + else +@@ -1245,21 +1248,21 @@ gtls_connect_step3(struct connectdata *conn, + gnutls_x509_crt_t format */ + gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER); + +- if(SSL_SET_OPTION(issuercert)) { ++ if(SSL_CONN_CONFIG(issuercert)) { + gnutls_x509_crt_init(&x509_issuer); +- issuerp = load_file(SSL_SET_OPTION(issuercert)); ++ issuerp = load_file(SSL_CONN_CONFIG(issuercert)); + gnutls_x509_crt_import(x509_issuer, &issuerp, GNUTLS_X509_FMT_PEM); + rc = gnutls_x509_crt_check_issuer(x509_cert, x509_issuer); + gnutls_x509_crt_deinit(x509_issuer); + unload_file(issuerp); + if(rc <= 0) { + failf(data, "server certificate issuer check failed (IssuerCert: %s)", +- SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none"); ++ SSL_CONN_CONFIG(issuercert)?SSL_CONN_CONFIG(issuercert):"none"); + gnutls_x509_crt_deinit(x509_cert); + return CURLE_SSL_ISSUER_ERROR; + } + infof(data, "\t server certificate issuer check OK (Issuer Cert: %s)\n", +- SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none"); ++ SSL_CONN_CONFIG(issuercert)?SSL_CONN_CONFIG(issuercert):"none"); + } + + size = sizeof(certbuf); +@@ -1490,7 +1493,8 @@ gtls_connect_step3(struct connectdata *conn, + gnutls_session_get_data(session, connect_sessionid, &connect_idsize); + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, NULL, + sockindex)); + if(incache) { + /* there was one before in the cache, so instead of risking that the +@@ -1499,7 +1503,8 @@ gtls_connect_step3(struct connectdata *conn, + } + + /* store this session id */ +- result = Curl_ssl_addsessionid(conn, connect_sessionid, connect_idsize, ++ result = Curl_ssl_addsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ connect_sessionid, connect_idsize, + sockindex); + Curl_ssl_sessionid_unlock(conn); + if(result) { +@@ -1705,8 +1710,8 @@ static int Curl_gtls_shutdown(struct connectdata *conn, int sockindex) + gnutls_certificate_free_credentials(BACKEND->cred); + + #ifdef USE_TLS_SRP +- if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP +- && SSL_SET_OPTION(username) != NULL) ++ if(SSL_SET_OPTION(primary.authtype) == CURL_TLSAUTH_SRP ++ && SSL_SET_OPTION(primary.username) != NULL) + gnutls_srp_free_client_credentials(BACKEND->srp_client_cred); + #endif + +diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c +index e34ec9d..783ecd9 100644 +--- a/lib/vtls/mbedtls.c ++++ b/lib/vtls/mbedtls.c +@@ -453,7 +453,8 @@ mbed_connect_step1(struct connectdata *conn, + void *old_session = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &old_session, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &old_session, NULL, sockindex)) { + ret = mbedtls_ssl_set_session(&BACKEND->ssl, old_session); + if(ret) { + Curl_ssl_sessionid_unlock(conn); +@@ -709,6 +710,7 @@ mbed_connect_step3(struct connectdata *conn, + int ret; + mbedtls_ssl_session *our_ssl_sessionid; + void *old_ssl_sessionid = NULL; ++ bool isproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + our_ssl_sessionid = malloc(sizeof(mbedtls_ssl_session)); + if(!our_ssl_sessionid) +@@ -727,10 +729,10 @@ mbed_connect_step3(struct connectdata *conn, + + /* If there's already a matching session in the cache, delete it */ + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, sockindex)) ++ if(!Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, NULL, sockindex)) + Curl_ssl_delsessionid(conn, old_ssl_sessionid); + +- retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid, 0, sockindex); ++ retcode = Curl_ssl_addsessionid(conn, isproxy, our_ssl_sessionid, 0, sockindex); + Curl_ssl_sessionid_unlock(conn); + if(retcode) { + mbedtls_ssl_session_free(our_ssl_sessionid); +diff --git a/lib/vtls/mesalink.c b/lib/vtls/mesalink.c +index cab1e39..79d1e3d 100644 +--- a/lib/vtls/mesalink.c ++++ b/lib/vtls/mesalink.c +@@ -263,7 +263,8 @@ mesalink_connect_step1(struct connectdata *conn, int sockindex) + void *ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + Curl_ssl_sessionid_unlock(conn); +@@ -347,12 +348,14 @@ mesalink_connect_step3(struct connectdata *conn, int sockindex) + bool incache; + SSL_SESSION *our_ssl_sessionid; + void *old_ssl_sessionid = NULL; ++ bool inproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + our_ssl_sessionid = SSL_get_session(BACKEND->handle); + + Curl_ssl_sessionid_lock(conn); + incache = +- !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, sockindex)); ++ !(Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, ++ NULL, sockindex)); + if(incache) { + if(old_ssl_sessionid != our_ssl_sessionid) { + infof(data, "old SSL session ID is stale, removing\n"); +@@ -363,7 +366,7 @@ mesalink_connect_step3(struct connectdata *conn, int sockindex) + + if(!incache) { + result = Curl_ssl_addsessionid( +- conn, our_ssl_sessionid, 0 /* unknown size */, sockindex); ++ conn, isproxy, our_ssl_sessionid, 0 /* unknown size */, sockindex); + if(result) { + Curl_ssl_sessionid_unlock(conn); + failf(data, "failed to store ssl session"); +diff --git a/lib/vtls/nss.c b/lib/vtls/nss.c +index ef51b0d..af8706c 100644 +--- a/lib/vtls/nss.c ++++ b/lib/vtls/nss.c +@@ -950,6 +950,9 @@ static void display_cert_info(struct Curl_easy *data, + PR_Free(common_name); + } + ++/* A number of certs that will never occur in a real server handshake */ ++#define TOO_MANY_CERTS 300 ++ + static CURLcode display_conn_info(struct connectdata *conn, PRFileDesc *sock) + { + CURLcode result = CURLE_OK; +@@ -986,6 +989,11 @@ static CURLcode display_conn_info(struct connectdata *conn, PRFileDesc *sock) + cert2 = CERT_FindCertIssuer(cert, now, certUsageSSLCA); + while(cert2) { + i++; ++ if(i >= TOO_MANY_CERTS) { ++ CERT_DestroyCertificate(cert2); ++ failf(conn->data, "certificate loop"); ++ return CURLE_SSL_CERTPROBLEM; ++ } + if(cert2->isRoot) { + CERT_DestroyCertificate(cert2); + break; +@@ -1947,13 +1955,13 @@ static CURLcode nss_setup_connect(struct connectdata *conn, int sockindex) + } + } + +- if(SSL_SET_OPTION(CRLfile)) { +- const CURLcode rv = nss_load_crl(SSL_SET_OPTION(CRLfile)); ++ if(SSL_SET_OPTION(primary.CRLfile)) { ++ const CURLcode rv = nss_load_crl(SSL_SET_OPTION(primary.CRLfile)); + if(rv) { + result = rv; + goto error; + } +- infof(data, " CRLfile: %s\n", SSL_SET_OPTION(CRLfile)); ++ infof(data, " CRLfile: %s\n", SSL_SET_OPTION(primary.CRLfile)); + } + + if(SSL_SET_OPTION(cert)) { +@@ -2151,9 +2159,9 @@ static CURLcode nss_do_connect(struct connectdata *conn, int sockindex) + if(result) + goto error; + +- if(SSL_SET_OPTION(issuercert)) { ++ if(SSL_CONN_CONFIG(issuercert)) { + SECStatus ret = SECFailure; +- char *nickname = dup_nickname(data, SSL_SET_OPTION(issuercert)); ++ char *nickname = dup_nickname(data, SSL_CONN_CONFIG(issuercert)); + if(nickname) { + /* we support only nicknames in case of issuercert for now */ + ret = check_issuer_cert(BACKEND->handle, nickname); +diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c +index 726ff6e..23f9ce0 100644 +--- a/lib/vtls/openssl.c ++++ b/lib/vtls/openssl.c +@@ -422,12 +422,23 @@ static int ossl_get_ssl_conn_index(void) + */ + static int ossl_get_ssl_sockindex_index(void) + { +- static int ssl_ex_data_sockindex_index = -1; +- if(ssl_ex_data_sockindex_index < 0) { +- ssl_ex_data_sockindex_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, +- NULL); ++ static int sockindex_index = -1; ++ if(sockindex_index < 0) { ++ sockindex_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); + } +- return ssl_ex_data_sockindex_index; ++ return sockindex_index; ++} ++ ++/* Return an extra data index for proxy boolean. ++ * This index can be used with SSL_get_ex_data() and SSL_set_ex_data(). ++ */ ++static int ossl_get_proxy_index(void) ++{ ++ static int proxy_index = -1; ++ if(proxy_index < 0) { ++ proxy_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL); ++ } ++ return proxy_index; + } + + static int passwd_callback(char *buf, int num, int encrypting, +@@ -1025,6 +1036,21 @@ static int Curl_ossl_init(void) + char *keylog_file_name; + #endif + ++#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \ ++ !defined(LIBRESSL_VERSION_NUMBER) ++ const uint64_t flags = ++#ifdef OPENSSL_INIT_ENGINE_ALL_BUILTIN ++ /* not present in BoringSSL */ ++ OPENSSL_INIT_ENGINE_ALL_BUILTIN | ++#endif ++#ifdef CURL_DISABLE_OPENSSL_AUTO_LOAD_CONFIG ++ OPENSSL_INIT_NO_LOAD_CONFIG | ++#else ++ OPENSSL_INIT_LOAD_CONFIG | ++#endif ++ 0; ++ OPENSSL_init_ssl(flags, NULL); ++#else + OPENSSL_load_builtin_modules(); + + #ifdef USE_OPENSSL_ENGINE +@@ -1043,10 +1069,6 @@ static int Curl_ossl_init(void) + CONF_MFLAGS_IGNORE_MISSING_FILE); + #endif + +-#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && \ +- !defined(LIBRESSL_VERSION_NUMBER) +- /* OpenSSL 1.1.0+ takes care of initialization itself */ +-#else + /* Lets get nice error messages */ + SSL_load_error_strings(); + +@@ -1079,7 +1101,8 @@ static int Curl_ossl_init(void) + #endif + + /* Initialize the extra data indexes */ +- if(ossl_get_ssl_conn_index() < 0 || ossl_get_ssl_sockindex_index() < 0) ++ if(ossl_get_ssl_conn_index() < 0 || ossl_get_ssl_sockindex_index() < 0 || ++ ossl_get_proxy_index() < 0) + return 0; + + return 1; +@@ -1717,6 +1740,11 @@ static CURLcode verifystatus(struct connectdata *conn, + OCSP_BASICRESP *br = NULL; + X509_STORE *st = NULL; + STACK_OF(X509) *ch = NULL; ++ X509 *cert; ++ OCSP_CERTID *id = NULL; ++ int cert_status, crl_reason; ++ ASN1_GENERALIZEDTIME *rev, *thisupd, *nextupd; ++ int ret; + + long len = SSL_get_tlsext_status_ocsp_resp(BACKEND->handle, &status); + +@@ -1785,43 +1813,63 @@ static CURLcode verifystatus(struct connectdata *conn, + goto end; + } + +- for(i = 0; i < OCSP_resp_count(br); i++) { +- int cert_status, crl_reason; +- OCSP_SINGLERESP *single = NULL; +- +- ASN1_GENERALIZEDTIME *rev, *thisupd, *nextupd; ++ /* Compute the certificate's ID */ ++ cert = SSL_get_peer_certificate(BACKEND->handle); ++ if(!cert) { ++ failf(data, "Error getting peer certficate"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- single = OCSP_resp_get0(br, i); +- if(!single) +- continue; ++ for(i = 0; i < sk_X509_num(ch); i++) { ++ X509 *issuer = sk_X509_value(ch, i); ++ if(X509_check_issued(issuer, cert) == X509_V_OK) { ++ id = OCSP_cert_to_id(EVP_sha1(), cert, issuer); ++ break; ++ } ++ } ++ X509_free(cert); + +- cert_status = OCSP_single_get0_status(single, &crl_reason, &rev, +- &thisupd, &nextupd); ++ if(!id) { ++ failf(data, "Error computing OCSP ID"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)) { +- failf(data, "OCSP response has expired"); +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; +- } ++ /* Find the single OCSP response corresponding to the certificate ID */ ++ ret = OCSP_resp_find_status(br, id, &cert_status, &crl_reason, &rev, ++ &thisupd, &nextupd); ++ OCSP_CERTID_free(id); ++ if(ret != 1) { ++ failf(data, "Could not find certificate ID in OCSP response"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- infof(data, "SSL certificate status: %s (%d)\n", +- OCSP_cert_status_str(cert_status), cert_status); ++ /* Validate the corresponding single OCSP response */ ++ if(!OCSP_check_validity(thisupd, nextupd, 300L, -1L)) { ++ failf(data, "OCSP response has expired"); ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; ++ } + +- switch(cert_status) { +- case V_OCSP_CERTSTATUS_GOOD: +- break; ++ infof(data, "SSL certificate status: %s (%d)\n", ++ OCSP_cert_status_str(cert_status), cert_status); + +- case V_OCSP_CERTSTATUS_REVOKED: +- result = CURLE_SSL_INVALIDCERTSTATUS; ++ switch(cert_status) { ++ case V_OCSP_CERTSTATUS_GOOD: ++ break; + +- failf(data, "SSL certificate revocation reason: %s (%d)", +- OCSP_crl_reason_str(crl_reason), crl_reason); +- goto end; ++ case V_OCSP_CERTSTATUS_REVOKED: ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ failf(data, "SSL certificate revocation reason: %s (%d)", ++ OCSP_crl_reason_str(crl_reason), crl_reason); ++ goto end; + +- case V_OCSP_CERTSTATUS_UNKNOWN: +- result = CURLE_SSL_INVALIDCERTSTATUS; +- goto end; +- } ++ case V_OCSP_CERTSTATUS_UNKNOWN: ++ default: ++ result = CURLE_SSL_INVALIDCERTSTATUS; ++ goto end; + } + + end: +@@ -2342,8 +2390,10 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + curl_socket_t *sockindex_ptr; + int connectdata_idx = ossl_get_ssl_conn_index(); + int sockindex_idx = ossl_get_ssl_sockindex_index(); ++ int proxy_idx = ossl_get_proxy_index(); ++ bool isproxy; + +- if(connectdata_idx < 0 || sockindex_idx < 0) ++ if(connectdata_idx < 0 || sockindex_idx < 0 || proxy_idx < 0) + return 0; + + conn = (struct connectdata*) SSL_get_ex_data(ssl, connectdata_idx); +@@ -2356,13 +2406,18 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + sockindex_ptr = (curl_socket_t*) SSL_get_ex_data(ssl, sockindex_idx); + sockindex = (int)(sockindex_ptr - conn->sock); + ++ isproxy = SSL_get_ex_data(ssl, proxy_idx) ? TRUE : FALSE; ++ + if(SSL_SET_OPTION(primary.sessionid)) { + bool incache; + void *old_ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, +- sockindex)); ++ if(isproxy) ++ incache = FALSE; ++ else ++ incache = !(Curl_ssl_getsessionid(conn, isproxy, ++ &old_ssl_sessionid, NULL, sockindex)); + if(incache) { + if(old_ssl_sessionid != ssl_sessionid) { + infof(data, "old SSL session ID is stale, removing\n"); +@@ -2372,7 +2427,7 @@ static int ossl_new_session_cb(SSL *ssl, SSL_SESSION *ssl_sessionid) + } + + if(!incache) { +- if(!Curl_ssl_addsessionid(conn, ssl_sessionid, ++ if(!Curl_ssl_addsessionid(conn, isproxy, ssl_sessionid, + 0 /* unknown size */, sockindex)) { + /* the session has been put into the session cache */ + res = 1; +@@ -2411,14 +2466,14 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + &data->set.proxy_ssl.certverifyresult : &data->set.ssl.certverifyresult; + const long int ssl_version = SSL_CONN_CONFIG(version); + #ifdef USE_TLS_SRP +- const enum CURL_TLSAUTH ssl_authtype = SSL_SET_OPTION(authtype); ++ const enum CURL_TLSAUTH ssl_authtype = SSL_SET_OPTION(primary.authtype); + #endif + char * const ssl_cert = SSL_SET_OPTION(cert); + const char * const ssl_cert_type = SSL_SET_OPTION(cert_type); + const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile); + const char * const ssl_capath = SSL_CONN_CONFIG(CApath); + const bool verifypeer = SSL_CONN_CONFIG(verifypeer); +- const char * const ssl_crlfile = SSL_SET_OPTION(CRLfile); ++ const char * const ssl_crlfile = SSL_SET_OPTION(primary.CRLfile); + char error_buffer[256]; + + DEBUGASSERT(ssl_connect_1 == connssl->connecting_state); +@@ -2697,15 +2752,15 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + + #ifdef USE_TLS_SRP + if(ssl_authtype == CURL_TLSAUTH_SRP) { +- char * const ssl_username = SSL_SET_OPTION(username); +- ++ char * const ssl_username = SSL_SET_OPTION(primary.username); ++ char * const ssl_password = SSL_SET_OPTION(primary.password); + infof(data, "Using TLS-SRP username: %s\n", ssl_username); + + if(!SSL_CTX_set_srp_username(BACKEND->ctx, ssl_username)) { + failf(data, "Unable to set SRP user name"); + return CURLE_BAD_FUNCTION_ARGUMENT; + } +- if(!SSL_CTX_set_srp_password(BACKEND->ctx, SSL_SET_OPTION(password))) { ++ if(!SSL_CTX_set_srp_password(BACKEND->ctx, ssl_password)) { + failf(data, "failed setting SRP password"); + return CURLE_BAD_FUNCTION_ARGUMENT; + } +@@ -2869,16 +2924,25 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex) + void *ssl_sessionid = NULL; + int connectdata_idx = ossl_get_ssl_conn_index(); + int sockindex_idx = ossl_get_ssl_sockindex_index(); ++ int proxy_idx = ossl_get_proxy_index(); + +- if(connectdata_idx >= 0 && sockindex_idx >= 0) { ++ if(connectdata_idx >= 0 && sockindex_idx >= 0 && proxy_idx >= 0) { + /* Store the data needed for the "new session" callback. + * The sockindex is stored as a pointer to an array element. */ + SSL_set_ex_data(BACKEND->handle, connectdata_idx, conn); + SSL_set_ex_data(BACKEND->handle, sockindex_idx, conn->sock + sockindex); ++#ifndef CURL_DISABLE_PROXY ++ SSL_set_ex_data(BACKEND->handle, proxy_idx, SSL_IS_PROXY() ? (void *) 1: ++ NULL); ++#else ++ SSL_set_ex_data(BACKEND->handle, proxy_idx, NULL); ++#endif ++ + } + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + Curl_ssl_sessionid_unlock(conn); +@@ -3539,7 +3603,7 @@ static CURLcode servercert(struct connectdata *conn, + deallocating the certificate. */ + + /* e.g. match issuer name with provided issuer certificate */ +- if(SSL_SET_OPTION(issuercert)) { ++ if(SSL_CONN_CONFIG(issuercert)) { + fp = BIO_new(BIO_s_file()); + if(fp == NULL) { + failf(data, +@@ -3552,10 +3616,10 @@ static CURLcode servercert(struct connectdata *conn, + return CURLE_OUT_OF_MEMORY; + } + +- if(BIO_read_filename(fp, SSL_SET_OPTION(issuercert)) <= 0) { ++ if(BIO_read_filename(fp, SSL_CONN_CONFIG(issuercert)) <= 0) { + if(strict) + failf(data, "SSL: Unable to open issuer cert (%s)", +- SSL_SET_OPTION(issuercert)); ++ SSL_CONN_CONFIG(issuercert)); + BIO_free(fp); + X509_free(BACKEND->server_cert); + BACKEND->server_cert = NULL; +@@ -3566,7 +3630,7 @@ static CURLcode servercert(struct connectdata *conn, + if(!issuer) { + if(strict) + failf(data, "SSL: Unable to read issuer cert (%s)", +- SSL_SET_OPTION(issuercert)); ++ SSL_CONN_CONFIG(issuercert)); + BIO_free(fp); + X509_free(issuer); + X509_free(BACKEND->server_cert); +@@ -3577,7 +3641,7 @@ static CURLcode servercert(struct connectdata *conn, + if(X509_check_issued(issuer, BACKEND->server_cert) != X509_V_OK) { + if(strict) + failf(data, "SSL: Certificate issuer check failed (%s)", +- SSL_SET_OPTION(issuercert)); ++ SSL_CONN_CONFIG(issuercert)); + BIO_free(fp); + X509_free(issuer); + X509_free(BACKEND->server_cert); +@@ -3586,7 +3650,7 @@ static CURLcode servercert(struct connectdata *conn, + } + + infof(data, " SSL certificate issuer check ok (%s)\n", +- SSL_SET_OPTION(issuercert)); ++ SSL_CONN_CONFIG(issuercert)); + BIO_free(fp); + X509_free(issuer); + } +diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c +index dc58ed0..f0aa727 100644 +--- a/lib/vtls/schannel.c ++++ b/lib/vtls/schannel.c +@@ -497,7 +497,8 @@ schannel_connect_step1(struct connectdata *conn, int sockindex) + /* check for an existing re-usable credential handle */ + if(SSL_SET_OPTION(primary.sessionid)) { + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ (void **)&old_cred, NULL, sockindex)) { + BACKEND->cred = old_cred; + DEBUGF(infof(data, "schannel: re-using existing credential handle\n")); + +@@ -1203,8 +1204,9 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + struct ssl_connect_data *connssl = &conn->ssl[sockindex]; + SECURITY_STATUS sspi_status = SEC_E_OK; + CERT_CONTEXT *ccert_context = NULL; ++ bool isproxy = SSL_IS_PROXY(); + #ifdef DEBUGBUILD +- const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name : ++ const char * const hostname = isproxy ? conn->http_proxy.host.name : + conn->host.name; + #endif + #ifdef HAS_ALPN +@@ -1278,7 +1280,7 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + struct curl_schannel_cred *old_cred = NULL; + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, (void **)&old_cred, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, isproxy, (void **)&old_cred, NULL, + sockindex)); + if(incache) { + if(old_cred != BACKEND->cred) { +@@ -1290,7 +1292,7 @@ schannel_connect_step3(struct connectdata *conn, int sockindex) + } + } + if(!incache) { +- result = Curl_ssl_addsessionid(conn, (void *)BACKEND->cred, ++ result = Curl_ssl_addsessionid(conn, isproxy, (void *)BACKEND->cred, + sizeof(struct curl_schannel_cred), + sockindex); + if(result) { +diff --git a/lib/vtls/sectransp.c b/lib/vtls/sectransp.c +index 4eece89..1c05607 100644 +--- a/lib/vtls/sectransp.c ++++ b/lib/vtls/sectransp.c +@@ -1376,7 +1376,8 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile); + const bool verifypeer = SSL_CONN_CONFIG(verifypeer); + char * const ssl_cert = SSL_SET_OPTION(cert); +- const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name : ++ bool isproxy = SSL_IS_PROXY(); ++ const char * const hostname = isproxy ? conn->http_proxy.host.name : + conn->host.name; + const long int port = SSL_IS_PROXY() ? conn->port : conn->remote_port; + #ifdef ENABLE_IPV6 +@@ -1584,7 +1585,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + + #ifdef USE_NGHTTP2 + if(data->set.httpversion >= CURL_HTTP_VERSION_2 && +- (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)) { ++ (!isproxy || !conn->bits.tunnel_proxy)) { + CFArrayAppendValue(alpnArr, CFSTR(NGHTTP2_PROTO_VERSION_ID)); + infof(data, "ALPN, offering %s\n", NGHTTP2_PROTO_VERSION_ID); + } +@@ -1916,7 +1917,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + size_t ssl_sessionid_len; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, (void **)&ssl_sessionid, ++ if(!Curl_ssl_getsessionid(conn, isproxy, (void **)&ssl_sessionid, + &ssl_sessionid_len, sockindex)) { + /* we got a session id, use it! */ + err = SSLSetPeerID(BACKEND->ssl_ctx, ssl_sessionid, ssl_sessionid_len); +@@ -1944,7 +1945,7 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + return CURLE_SSL_CONNECT_ERROR; + } + +- result = Curl_ssl_addsessionid(conn, ssl_sessionid, ssl_sessionid_len, ++ result = Curl_ssl_addsessionid(conn, isproxy, ssl_sessionid, ssl_sessionid_len, + sockindex); + Curl_ssl_sessionid_unlock(conn); + if(result) { +diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c +index c493b15..557c8d3 100644 +--- a/lib/vtls/vtls.c ++++ b/lib/vtls/vtls.c +@@ -82,22 +82,40 @@ + else \ + dest->var = NULL; + ++static bool safecmp(char *a, char *b) ++{ ++ if(a && b) ++ return !strcmp(a, b); ++ else if(!a && !b) ++ return TRUE; /* match */ ++ return FALSE; /* no match */ ++} ++ ++ + bool + Curl_ssl_config_matches(struct ssl_primary_config* data, + struct ssl_primary_config* needle) + { + if((data->version == needle->version) && + (data->version_max == needle->version_max) && ++ (data->ssl_options == needle->ssl_options) && + (data->verifypeer == needle->verifypeer) && + (data->verifyhost == needle->verifyhost) && + (data->verifystatus == needle->verifystatus) && +- Curl_safe_strcasecompare(data->CApath, needle->CApath) && +- Curl_safe_strcasecompare(data->CAfile, needle->CAfile) && +- Curl_safe_strcasecompare(data->clientcert, needle->clientcert) && +- Curl_safe_strcasecompare(data->random_file, needle->random_file) && +- Curl_safe_strcasecompare(data->egdsocket, needle->egdsocket) && ++ safecmp(data->CApath, needle->CApath) && ++ safecmp(data->CAfile, needle->CAfile) && ++ safecmp(data->issuercert, needle->issuercert) && ++ safecmp(data->clientcert, needle->clientcert) && ++ safecmp(data->random_file, needle->random_file) && ++ safecmp(data->egdsocket, needle->egdsocket) && ++#ifdef USE_TLS_SRP ++ Curl_safecmp(data->username, needle->username) && ++ Curl_safecmp(data->password, needle->password) && ++ (data->authtype == needle->authtype) && ++#endif + Curl_safe_strcasecompare(data->cipher_list, needle->cipher_list) && + Curl_safe_strcasecompare(data->cipher_list13, needle->cipher_list13) && ++ Curl_safe_strcasecompare(data->CRLfile, needle->CRLfile) && + Curl_safe_strcasecompare(data->pinned_key, needle->pinned_key)) + return TRUE; + +@@ -114,15 +132,25 @@ Curl_clone_primary_ssl_config(struct ssl_primary_config *source, + dest->verifyhost = source->verifyhost; + dest->verifystatus = source->verifystatus; + dest->sessionid = source->sessionid; ++ dest->ssl_options = source->ssl_options; ++#ifdef USE_TLS_SRP ++ dest->authtype = source->authtype; ++#endif + + CLONE_STRING(CApath); + CLONE_STRING(CAfile); ++ CLONE_STRING(issuercert); + CLONE_STRING(clientcert); + CLONE_STRING(random_file); + CLONE_STRING(egdsocket); + CLONE_STRING(cipher_list); + CLONE_STRING(cipher_list13); + CLONE_STRING(pinned_key); ++ CLONE_STRING(CRLfile); ++#ifdef USE_TLS_SRP ++ CLONE_STRING(username); ++ CLONE_STRING(password); ++#endif + + return TRUE; + } +@@ -131,12 +159,18 @@ void Curl_free_primary_ssl_config(struct ssl_primary_config* sslc) + { + Curl_safefree(sslc->CApath); + Curl_safefree(sslc->CAfile); ++ Curl_safefree(sslc->issuercert); + Curl_safefree(sslc->clientcert); + Curl_safefree(sslc->random_file); + Curl_safefree(sslc->egdsocket); + Curl_safefree(sslc->cipher_list); + Curl_safefree(sslc->cipher_list13); + Curl_safefree(sslc->pinned_key); ++ Curl_safefree(sslc->CRLfile); ++#ifdef USE_TLS_SRP ++ Curl_safefree(sslc->username); ++ Curl_safefree(sslc->password); ++#endif + } + + #ifdef USE_SSL +@@ -305,6 +339,7 @@ void Curl_ssl_sessionid_unlock(struct connectdata *conn) + * there's one suitable, it is provided. Returns TRUE when no entry matched. + */ + bool Curl_ssl_getsessionid(struct connectdata *conn, ++ const bool isProxy, + void **ssl_sessionid, + size_t *idsize, /* set 0 if unknown */ + int sockindex) +@@ -315,7 +350,6 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + long *general_age; + bool no_match = TRUE; + +- const bool isProxy = CONNECT_PROXY_SSL(); + struct ssl_primary_config * const ssl_config = isProxy ? + &conn->proxy_ssl_config : + &conn->ssl_config; +@@ -324,6 +358,11 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + int port = isProxy ? (int)conn->port : conn->remote_port; + *ssl_sessionid = NULL; + ++#ifdef CURL_DISABLE_PROXY ++ if(isProxy) ++ return TRUE; ++#endif ++ + DEBUGASSERT(SSL_SET_OPTION(primary.sessionid)); + + if(!SSL_SET_OPTION(primary.sessionid)) +@@ -411,6 +450,7 @@ void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid) + * later on. + */ + CURLcode Curl_ssl_addsessionid(struct connectdata *conn, ++ bool isProxy, + void *ssl_sessionid, + size_t idsize, + int sockindex) +@@ -423,7 +463,6 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn, + char *clone_conn_to_host; + int conn_to_port; + long *general_age; +- const bool isProxy = CONNECT_PROXY_SSL(); + struct ssl_primary_config * const ssl_config = isProxy ? + &conn->proxy_ssl_config : + &conn->ssl_config; +diff --git a/lib/vtls/vtls.h b/lib/vtls/vtls.h +index 976cc43..9fed5a0 100644 +--- a/lib/vtls/vtls.h ++++ b/lib/vtls/vtls.h +@@ -203,6 +203,7 @@ void Curl_ssl_sessionid_unlock(struct connectdata *conn); + * under sessionid mutex). + */ + bool Curl_ssl_getsessionid(struct connectdata *conn, ++ const bool isproxy, + void **ssl_sessionid, + size_t *idsize, /* set 0 if unknown */ + int sockindex); +@@ -212,6 +213,7 @@ bool Curl_ssl_getsessionid(struct connectdata *conn, + * object with cache (e.g. incrementing refcount on success) + */ + CURLcode Curl_ssl_addsessionid(struct connectdata *conn, ++ const bool isProxy, + void *ssl_sessionid, + size_t idsize, + int sockindex); +diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c +index 890bcbf..c772bd5 100644 +--- a/lib/vtls/wolfssl.c ++++ b/lib/vtls/wolfssl.c +@@ -392,7 +392,8 @@ wolfssl_connect_step1(struct connectdata *conn, + void *ssl_sessionid = NULL; + + Curl_ssl_sessionid_lock(conn); +- if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL, sockindex)) { ++ if(!Curl_ssl_getsessionid(conn, SSL_IS_PROXY() ? TRUE : FALSE, ++ &ssl_sessionid, NULL, sockindex)) { + /* we got a session id, use it! */ + if(!SSL_set_session(BACKEND->handle, ssl_sessionid)) { + char error_buffer[WOLFSSL_MAX_ERROR_SZ]; +@@ -618,9 +619,10 @@ wolfssl_connect_step3(struct connectdata *conn, + void *old_ssl_sessionid = NULL; + + our_ssl_sessionid = SSL_get_session(BACKEND->handle); ++ bool isproxy = SSL_IS_PROXY() ? TRUE : FALSE; + + Curl_ssl_sessionid_lock(conn); +- incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL, ++ incache = !(Curl_ssl_getsessionid(conn, isproxy, &old_ssl_sessionid, NULL, + sockindex)); + if(incache) { + if(old_ssl_sessionid != our_ssl_sessionid) { +@@ -631,7 +633,7 @@ wolfssl_connect_step3(struct connectdata *conn, + } + + if(!incache) { +- result = Curl_ssl_addsessionid(conn, our_ssl_sessionid, ++ result = Curl_ssl_addsessionid(conn, isproxy, our_ssl_sessionid, + 0 /* unknown size */, sockindex); + if(result) { + Curl_ssl_sessionid_unlock(conn); +diff --git a/src/tool_cb_hdr.c b/src/tool_cb_hdr.c +index 77224ad..e0784c6 100644 +--- a/src/tool_cb_hdr.c ++++ b/src/tool_cb_hdr.c +@@ -188,25 +188,11 @@ size_t tool_header_cb(char *ptr, size_t size, size_t nmemb, void *userdata) + filename = parse_filename(p, len); + if(filename) { + if(outs->stream) { +- int rc; +- /* already opened and possibly written to */ +- if(outs->fopened) +- fclose(outs->stream); +- outs->stream = NULL; +- +- /* rename the initial file name to the new file name */ +- rc = rename(outs->filename, filename); +- if(rc != 0) { +- warnf(outs->config->global, "Failed to rename %s -> %s: %s\n", +- outs->filename, filename, strerror(errno)); +- } +- if(outs->alloc_filename) +- Curl_safefree(outs->filename); +- if(rc != 0) { +- free(filename); +- return failure; +- } ++ /* indication of problem, get out! */ ++ free(filename); ++ return failure; + } ++ + outs->is_cd_filename = TRUE; + outs->s_isreg = TRUE; + outs->fopened = FALSE; +diff --git a/src/tool_cfgable.c b/src/tool_cfgable.c +index f802a5a..d492b58 100644 +--- a/src/tool_cfgable.c ++++ b/src/tool_cfgable.c +@@ -44,6 +44,7 @@ void config_init(struct OperationConfig* config) + config->tcp_nodelay = TRUE; /* enabled by default */ + config->happy_eyeballs_timeout_ms = CURL_HET_DEFAULT; + config->http09_allowed = FALSE; ++ config->ftp_skip_ip = TRUE; + } + + static void free_config_fields(struct OperationConfig *config) +diff --git a/src/tool_getparam.c b/src/tool_getparam.c +index 8df6e5e..8191ed5 100644 +--- a/src/tool_getparam.c ++++ b/src/tool_getparam.c +@@ -1800,6 +1800,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ + } + break; + case 'i': ++ if(config->content_disposition) { ++ warnf(global, ++ "--include and --remote-header-name cannot be combined.\n"); ++ return PARAM_BAD_USE; ++ } + config->show_headers = toggle; /* show the headers as well in the + general output stream */ + break; +diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc +index 09cb057..52bdaec 100644 +--- a/tests/data/Makefile.inc ++++ b/tests/data/Makefile.inc +@@ -111,6 +111,11 @@ test936 test937 test938 test939 test940 test941 test942 test943 test944 \ + test945 test946 test947 test948 test949 test950 test951 test952 test953 \ + test954 \ + \ ++test973 test974 test975 test976 \ ++test980 test981 test982 test983 \ ++\ ++test984 test985 test986 \ ++\ + test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 \ + test1008 test1009 test1010 test1011 test1012 test1013 test1014 test1015 \ + test1016 test1017 test1018 test1019 test1020 test1021 test1022 test1023 \ +@@ -131,7 +136,7 @@ test1128 test1129 test1130 test1131 test1132 test1133 test1134 test1135 \ + test1136 test1137 test1138 test1139 test1140 test1141 test1142 test1143 \ + test1144 test1145 test1146 test1147 test1148 test1149 test1150 test1151 \ + test1152 test1153 test1154 test1155 test1156 test1157 test1158 test1159 \ +-test1160 test1161 test1162 test1163 test1164 test1165 test1166 \ ++test1160 test1161 test1162 test1163 test1164 test1165 test1166 test1168 \ + test1170 test1171 test1172 test1173 test1174 test1175 \ + \ + test1200 test1201 test1202 test1203 test1204 test1205 test1206 test1207 \ +diff --git a/tests/data/test1168 b/tests/data/test1168 +new file mode 100644 +index 0000000..283e91e +--- /dev/null ++++ b/tests/data/test1168 +@@ -0,0 +1,78 @@ ++ ++ ++ ++HTTP ++HTTP GET ++followlocation ++ ++ ++# Server-side ++ ++ ++HTTP/1.1 301 This is a weirdo text message swsclose ++Date: Thu, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Location: /data/11680002.txt ++Connection: close ++ ++This server reply is for testing a simple Location: following ++ ++ ++ ++HTTP/1.1 200 Followed here fine swsclose ++Date: Thu, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 52 ++ ++If this is received, the location following worked ++ ++ ++ ++HTTP/1.1 301 This is a weirdo text message swsclose ++Date: Thu, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Location: /data/11680002.txt ++Connection: close ++ ++HTTP/1.1 200 Followed here fine swsclose ++Date: Thu, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 52 ++ ++If this is received, the location following worked ++ ++ ++ ++ ++# Client-side ++ ++ ++http ++ ++ ++HTTP redirect with credentials using # in user and password ++ ++ ++http://%HOSTIP:%HTTPPORT/want/1168 -L -u "catmai#d:#DZaRJYrixKE*gFY" ++ ++ ++ ++# Verify data after the test has been "shot" ++ ++ ++^User-Agent:.* ++ ++ ++GET /want/1168 HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++Authorization: Basic Y2F0bWFpI2Q6I0RaYVJKWXJpeEtFKmdGWQ== ++Accept: */* ++ ++GET /data/11680002.txt HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++Authorization: Basic Y2F0bWFpI2Q6I0RaYVJKWXJpeEtFKmdGWQ== ++Accept: */* ++ ++ ++ ++ +diff --git a/tests/data/test1400 b/tests/data/test1400 +index c0d409b..ade50d4 100644 +--- a/tests/data/test1400 ++++ b/tests/data/test1400 +@@ -76,6 +76,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1401 b/tests/data/test1401 +index ec3b25c..a2e9ef2 100644 +--- a/tests/data/test1401 ++++ b/tests/data/test1401 +@@ -90,6 +90,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_COOKIE, "chocolate=chip"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(hnd, CURLOPT_PROTOCOLS, (long)CURLPROTO_FILE | + (long)CURLPROTO_FTP | +diff --git a/tests/data/test1402 b/tests/data/test1402 +index bf7eb7b..99d4b70 100644 +--- a/tests/data/test1402 ++++ b/tests/data/test1402 +@@ -81,6 +81,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1403 b/tests/data/test1403 +index 731d274..90f9b4e 100644 +--- a/tests/data/test1403 ++++ b/tests/data/test1403 +@@ -76,6 +76,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1404 b/tests/data/test1404 +index d3c66a9..d351c3e 100644 +--- a/tests/data/test1404 ++++ b/tests/data/test1404 +@@ -147,6 +147,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); + curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1405 b/tests/data/test1405 +index dcc8f80..d1ebb7c 100644 +--- a/tests/data/test1405 ++++ b/tests/data/test1405 +@@ -89,6 +89,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_POSTQUOTE, slist2); + curl_easy_setopt(hnd, CURLOPT_PREQUOTE, slist3); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1406 b/tests/data/test1406 +index 8803c84..31db82a 100644 +--- a/tests/data/test1406 ++++ b/tests/data/test1406 +@@ -79,6 +79,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_URL, "smtp://%HOSTIP:%SMTPPORT/1406"); + curl_easy_setopt(hnd, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + curl_easy_setopt(hnd, CURLOPT_MAIL_FROM, "sender@example.com"); + curl_easy_setopt(hnd, CURLOPT_MAIL_RCPT, slist1); +diff --git a/tests/data/test1407 b/tests/data/test1407 +index 917a5de..d329509 100644 +--- a/tests/data/test1407 ++++ b/tests/data/test1407 +@@ -62,6 +62,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_DIRLISTONLY, 1L); + curl_easy_setopt(hnd, CURLOPT_USERPWD, "user:secret"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test1420 b/tests/data/test1420 +index 03c4584..c1ba190 100644 +--- a/tests/data/test1420 ++++ b/tests/data/test1420 +@@ -67,6 +67,7 @@ int main(int argc, char *argv[]) + curl_easy_setopt(hnd, CURLOPT_URL, "imap://%HOSTIP:%IMAPPORT/1420/;MAILINDEX=1"); + curl_easy_setopt(hnd, CURLOPT_USERPWD, "user:secret"); + curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); ++ curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L); + curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); + + /* Here is a list of options the curl code used that cannot get generated +diff --git a/tests/data/test973 b/tests/data/test973 +new file mode 100644 +index 0000000..e2f051d +--- /dev/null ++++ b/tests/data/test973 +@@ -0,0 +1,88 @@ ++ ++ ++ ++HTTP ++FTP ++--location ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: ftp://127.0.0.1:8992/a/path/9730002 ++ ++ ++ ++data ++ to ++ see ++that FTP ++works ++ so does it? ++ ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: ftp://127.0.0.1:8992/a/path/9730002 ++ ++data ++ to ++ see ++that FTP ++works ++ so does it? ++ ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ftp ++ ++ ++HTTP with auth redirected to FTP w/o auth ++ ++ ++http://%HOSTIP:%HTTPPORT/973 -L -u joe:secret ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++GET /973 HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++ ++USER anonymous ++PASS ftp@example.com ++PWD ++CWD a ++CWD path ++EPSV ++TYPE I ++SIZE 9730002 ++RETR 9730002 ++QUIT ++ ++ ++ +diff --git a/tests/data/test974 b/tests/data/test974 +new file mode 100644 +index 0000000..854200a +--- /dev/null ++++ b/tests/data/test974 +@@ -0,0 +1,87 @@ ++ ++ ++ ++HTTP ++--location ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: http://firsthost.974:9999/a/path/9740002 ++ ++ ++ ++HTTP/1.1 200 OK ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 4 ++Connection: close ++Content-Type: text/html ++ ++hey ++ ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: http://firsthost.974:9999/a/path/9740002 ++ ++HTTP/1.1 200 OK ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 4 ++Connection: close ++Content-Type: text/html ++ ++hey ++ ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ ++ ++HTTP with auth redirected to HTTP on a diff port w/o auth ++ ++ ++-x http://%HOSTIP:%HTTPPORT http://firsthost.974 -L -u joe:secret ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++GET http://firsthost.974/ HTTP/1.1 ++Host: firsthost.974 ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++Proxy-Connection: Keep-Alive ++ ++GET http://firsthost.974:9999/a/path/9740002 HTTP/1.1 ++Host: firsthost.974:9999 ++User-Agent: curl/7.68.0 ++Accept: */* ++Proxy-Connection: Keep-Alive ++ ++ ++ ++ +diff --git a/tests/data/test975 b/tests/data/test975 +new file mode 100644 +index 0000000..2ab23e9 +--- /dev/null ++++ b/tests/data/test975 +@@ -0,0 +1,88 @@ ++ ++ ++ ++HTTP ++FTP ++--location-trusted ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: ftp://127.0.0.1:8992/a/path/9750002 ++ ++ ++ ++data ++ to ++ see ++that FTP ++works ++ so does it? ++ ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: ftp://127.0.0.1:8992/a/path/9750002 ++ ++data ++ to ++ see ++that FTP ++works ++ so does it? ++ ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ftp ++ ++ ++HTTP with auth redirected to FTP allowing auth to continue ++ ++ ++http://%HOSTIP:%HTTPPORT/975 --location-trusted -u joe:secret ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++GET /975 HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++ ++USER joe ++PASS secret ++PWD ++CWD a ++CWD path ++EPSV ++TYPE I ++SIZE 9750002 ++RETR 9750002 ++QUIT ++ ++ ++ +diff --git a/tests/data/test976 b/tests/data/test976 +new file mode 100644 +index 0000000..65d51ce +--- /dev/null ++++ b/tests/data/test976 +@@ -0,0 +1,88 @@ ++ ++ ++ ++HTTP ++--location-trusted ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: http://firsthost.976:9999/a/path/9760002 ++ ++ ++ ++HTTP/1.1 200 OK ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 4 ++Connection: close ++Content-Type: text/html ++ ++hey ++ ++ ++ ++HTTP/1.1 301 redirect ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 0 ++Connection: close ++Content-Type: text/html ++Location: http://firsthost.976:9999/a/path/9760002 ++ ++HTTP/1.1 200 OK ++Date: Tue, 09 Nov 2010 14:49:00 GMT ++Server: test-server/fake ++Content-Length: 4 ++Connection: close ++Content-Type: text/html ++ ++hey ++ ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ ++ ++HTTP with auth redirected to HTTP on a diff port --location-trusted ++ ++ ++-x http://%HOSTIP:%HTTPPORT http://firsthost.976 --location-trusted -u joe:secret ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++GET http://firsthost.976/ HTTP/1.1 ++Host: firsthost.976 ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++Proxy-Connection: Keep-Alive ++ ++GET http://firsthost.976:9999/a/path/9760002 HTTP/1.1 ++Host: firsthost.976:9999 ++Authorization: Basic am9lOnNlY3JldA== ++User-Agent: curl/7.68.0 ++Accept: */* ++Proxy-Connection: Keep-Alive ++ ++ ++ ++ +diff --git a/tests/data/test980 b/tests/data/test980 +new file mode 100644 +index 0000000..97567f8 +--- /dev/null ++++ b/tests/data/test980 +@@ -0,0 +1,52 @@ ++ ++ ++ ++SMTP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++CAPA STARTTLS ++AUTH PLAIN ++REPLY STARTTLS 454 currently unavailable\r\n235 Authenticated\r\n250 2.1.0 Sender ok\r\n250 2.1.5 Recipient ok\r\n354 Enter mail\r\n250 2.0.0 Accepted ++REPLY AUTH 535 5.7.8 Authentication credentials invalid ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++smtp ++ ++ ++SMTP STARTTLS pipelined server response ++ ++ ++mail body ++ ++ ++smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com --mail-from sender@example.com -u user:secret --ssl --sasl-ir -T - ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 8 is CURLE_WEIRD_SERVER_REPLY ++ ++8 ++ ++ ++EHLO %TESTNUMBER ++STARTTLS ++ ++ ++ +diff --git a/tests/data/test981 b/tests/data/test981 +new file mode 100644 +index 0000000..2b98ce4 +--- /dev/null ++++ b/tests/data/test981 +@@ -0,0 +1,59 @@ ++ ++ ++ ++IMAP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++CAPA STARTTLS ++REPLY STARTTLS A002 BAD currently unavailable\r\nA003 OK Authenticated\r\nA004 OK Accepted ++REPLY LOGIN A003 BAD Authentication credentials invalid ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++imap ++ ++ ++IMAP STARTTLS pipelined server response ++ ++ ++imap://%HOSTIP:%IMAPPORT/%TESTNUMBER -T log/upload%TESTNUMBER -u user:secret --ssl ++ ++ ++Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST) ++From: Fred Foobar ++Subject: afternoon meeting ++To: joe@example.com ++Message-Id: ++MIME-Version: 1.0 ++Content-Type: TEXT/PLAIN; CHARSET=US-ASCII ++ ++Hello Joe, do you think we can meet at 3:30 tomorrow? ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 8 is CURLE_WEIRD_SERVER_REPLY ++ ++8 ++ ++ ++A001 CAPABILITY ++A002 STARTTLS ++ ++ ++ +diff --git a/tests/data/test982 b/tests/data/test982 +new file mode 100644 +index 0000000..9e07cc0 +--- /dev/null ++++ b/tests/data/test982 +@@ -0,0 +1,57 @@ ++ ++ ++ ++POP3 ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++CAPA STLS USER ++REPLY STLS -ERR currently unavailable\r\n+OK user accepted\r\n+OK authenticated ++REPLY PASS -ERR Authentication credentials invalid ++ ++ ++From: me@somewhere ++To: fake@nowhere ++ ++body ++ ++-- ++ yours sincerely ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++pop3 ++ ++ ++POP3 STARTTLS pipelined server response ++ ++ ++pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u user:secret --ssl ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 8 is CURLE_WEIRD_SERVER_REPLY ++ ++8 ++ ++ ++CAPA ++STLS ++ ++ ++ +diff --git a/tests/data/test983 b/tests/data/test983 +new file mode 100644 +index 0000000..300ec45 +--- /dev/null ++++ b/tests/data/test983 +@@ -0,0 +1,52 @@ ++ ++ ++ ++FTP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++REPLY AUTH 500 unknown command\r\n500 unknown command\r\n331 give password\r\n230 Authenticated\r\n257 "/"\r\n200 OK\r\n200 OK\r\n200 OK\r\n226 Transfer complete ++REPLY PASS 530 Login incorrect ++ ++ ++ ++# Client-side ++ ++ ++SSL ++ ++ ++ftp ++ ++ ++FTP STARTTLS pipelined server response ++ ++ ++data ++ to ++ see ++that FTPS ++works ++ so does it? ++ ++ ++--ssl --ftp-ssl-control ftp://%HOSTIP:%FTPPORT/%TESTNUMBER -T log/test%TESTNUMBER.txt -u user:secret -P %CLIENTIP ++ ++ ++ ++# Verify data after the test has been "shot" ++ ++# 8 is CURLE_WEIRD_SERVER_REPLY ++ ++8 ++ ++ ++AUTH SSL ++ ++ ++ +diff --git a/tests/data/test984 b/tests/data/test984 +new file mode 100644 +index 0000000..e573f23 +--- /dev/null ++++ b/tests/data/test984 +@@ -0,0 +1,56 @@ ++ ++ ++ ++IMAP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++REPLY CAPABILITY A001 BAD Not implemented ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++imap ++ ++ ++IMAP require STARTTLS with failing capabilities ++ ++ ++imap://%HOSTIP:%IMAPPORT/%TESTNUMBER -T log/upload%TESTNUMBER -u user:secret --ssl-reqd ++ ++ ++Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST) ++From: Fred Foobar ++Subject: afternoon meeting ++To: joe@example.com ++Message-Id: ++MIME-Version: 1.0 ++Content-Type: TEXT/PLAIN; CHARSET=US-ASCII ++ ++Hello Joe, do you think we can meet at 3:30 tomorrow? ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 64 is CURLE_USE_SSL_FAILED ++ ++64 ++ ++ ++A001 CAPABILITY ++ ++ ++ +diff --git a/tests/data/test985 b/tests/data/test985 +new file mode 100644 +index 0000000..d0db4aa +--- /dev/null ++++ b/tests/data/test985 +@@ -0,0 +1,54 @@ ++ ++ ++ ++POP3 ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++REPLY CAPA -ERR Not implemented ++ ++ ++From: me@somewhere ++To: fake@nowhere ++ ++body ++ ++-- ++ yours sincerely ++ ++ ++ ++# ++# Client-side ++ ++ ++SSL ++ ++ ++pop3 ++ ++ ++POP3 require STARTTLS with failing capabilities ++ ++ ++pop3://%HOSTIP:%POP3PORT/%TESTNUMBER -u user:secret --ssl-reqd ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++# 64 is CURLE_USE_SSL_FAILED ++ ++64 ++ ++ ++CAPA ++ ++ ++ +diff --git a/tests/data/test986 b/tests/data/test986 +new file mode 100644 +index 0000000..a709437 +--- /dev/null ++++ b/tests/data/test986 +@@ -0,0 +1,53 @@ ++ ++ ++ ++FTP ++STARTTLS ++ ++ ++ ++# ++# Server-side ++ ++ ++REPLY welcome 230 Welcome ++REPLY AUTH 500 unknown command ++ ++ ++ ++# Client-side ++ ++ ++SSL ++ ++ ++ftp ++ ++ ++FTP require STARTTLS while preauthenticated ++ ++ ++data ++ to ++ see ++that FTPS ++works ++ so does it? ++ ++ ++--ssl-reqd --ftp-ssl-control ftp://%HOSTIP:%FTPPORT/%TESTNUMBER -T log/test%TESTNUMBER.txt -u user:secret ++ ++ ++ ++# Verify data after the test has been "shot" ++ ++# 64 is CURLE_USE_SSL_FAILED ++ ++64 ++ ++ ++AUTH SSL ++AUTH TLS ++ ++ ++ diff --git a/debian/patches/0012-openldap-replace-ldap_-prefix-on-private-functions.patch b/debian/patches/0012-openldap-replace-ldap_-prefix-on-private-functions.patch new file mode 100644 index 0000000000000000000000000000000000000000..a56301cf0bdbd14d77b8f3b60b25bd546b3eaa21 --- /dev/null +++ b/debian/patches/0012-openldap-replace-ldap_-prefix-on-private-functions.patch @@ -0,0 +1,165 @@ +From: zhaikangning +Date: Mon, 24 Apr 2023 15:31:05 +0800 +Subject: =?utf-8?q?openldap=3A_replace_ldap=5F_prefix_on_private_functions_?= + =?utf-8?q?Since_openldap_itself_uses_that_prefix_and_with_Open=C4=B9DAP_2?= + =?utf-8?q?=2E5=2E4_=28at_least=29_there=27s_a_symbol_collision_because_of_?= + =?utf-8?q?that=2E?= +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +The private functions now use the 'oldap_' prefix where it previously +used 'ldap_'. + +github:https://github.com/curl/curl/pull/7005/commits +同步上游patch,解决编译问题:OpenĹDAP 2.5.4以及之后的版本因为部分函数命名冲突 +--- + lib/openldap.c | 54 +++++++++++++++++++++++++++--------------------------- + 1 file changed, 27 insertions(+), 27 deletions(-) + +diff --git a/lib/openldap.c b/lib/openldap.c +index 734ca5f..fe1840b 100644 +--- a/lib/openldap.c ++++ b/lib/openldap.c +@@ -76,14 +76,14 @@ extern int ldap_init_fd(ber_socket_t fd, int proto, const char *url, + LDAP **ld); + #endif + +-static CURLcode ldap_setup_connection(struct connectdata *conn); +-static CURLcode ldap_do(struct connectdata *conn, bool *done); +-static CURLcode ldap_done(struct connectdata *conn, CURLcode, bool); +-static CURLcode ldap_connect(struct connectdata *conn, bool *done); +-static CURLcode ldap_connecting(struct connectdata *conn, bool *done); +-static CURLcode ldap_disconnect(struct connectdata *conn, bool dead); ++static CURLcode oldap_setup_connection(struct connectdata *conn); ++static CURLcode oldap_do(struct connectdata *conn, bool *done); ++static CURLcode oldap_done(struct connectdata *conn, CURLcode, bool); ++static CURLcode oldap_connect(struct connectdata *conn, bool *done); ++static CURLcode oldap_connecting(struct connectdata *conn, bool *done); ++static CURLcode oldap_disconnect(struct connectdata *conn, bool dead); + +-static Curl_recv ldap_recv; ++static Curl_recv oldap_recv; + + /* + * LDAP protocol handler. +@@ -91,18 +91,18 @@ static Curl_recv ldap_recv; + + const struct Curl_handler Curl_handler_ldap = { + "LDAP", /* scheme */ +- ldap_setup_connection, /* setup_connection */ +- ldap_do, /* do_it */ +- ldap_done, /* done */ ++ oldap_setup_connection, /* setup_connection */ ++ oldap_do, /* do_it */ ++ oldap_done, /* done */ + ZERO_NULL, /* do_more */ +- ldap_connect, /* connect_it */ +- ldap_connecting, /* connecting */ ++ oldap_connect, /* connect_it */ ++ oldap_connecting, /* connecting */ + ZERO_NULL, /* doing */ + ZERO_NULL, /* proto_getsock */ + ZERO_NULL, /* doing_getsock */ + ZERO_NULL, /* domore_getsock */ + ZERO_NULL, /* perform_getsock */ +- ldap_disconnect, /* disconnect */ ++ oldap_disconnect, /* disconnect */ + ZERO_NULL, /* readwrite */ + ZERO_NULL, /* connection_check */ + PORT_LDAP, /* defport */ +@@ -117,18 +117,18 @@ const struct Curl_handler Curl_handler_ldap = { + + const struct Curl_handler Curl_handler_ldaps = { + "LDAPS", /* scheme */ +- ldap_setup_connection, /* setup_connection */ +- ldap_do, /* do_it */ +- ldap_done, /* done */ ++ oldap_setup_connection, /* setup_connection */ ++ oldap_do, /* do_it */ ++ oldap_done, /* done */ + ZERO_NULL, /* do_more */ +- ldap_connect, /* connect_it */ +- ldap_connecting, /* connecting */ ++ oldap_connect, /* connect_it */ ++ oldap_connecting, /* connecting */ + ZERO_NULL, /* doing */ + ZERO_NULL, /* proto_getsock */ + ZERO_NULL, /* doing_getsock */ + ZERO_NULL, /* domore_getsock */ + ZERO_NULL, /* perform_getsock */ +- ldap_disconnect, /* disconnect */ ++ oldap_disconnect, /* disconnect */ + ZERO_NULL, /* readwrite */ + ZERO_NULL, /* connection_check */ + PORT_LDAPS, /* defport */ +@@ -167,7 +167,7 @@ typedef struct ldapreqinfo { + int nument; + } ldapreqinfo; + +-static CURLcode ldap_setup_connection(struct connectdata *conn) ++static CURLcode oldap_setup_connection(struct connectdata *conn) + { + struct ldapconninfo *li; + LDAPURLDesc *lud; +@@ -203,7 +203,7 @@ static CURLcode ldap_setup_connection(struct connectdata *conn) + static Sockbuf_IO ldapsb_tls; + #endif + +-static CURLcode ldap_connect(struct connectdata *conn, bool *done) ++static CURLcode oldap_connect(struct connectdata *conn, bool *done) + { + struct ldapconninfo *li = conn->proto.ldapc; + struct Curl_easy *data = conn->data; +@@ -250,7 +250,7 @@ static CURLcode ldap_connect(struct connectdata *conn, bool *done) + return CURLE_OK; + } + +-static CURLcode ldap_connecting(struct connectdata *conn, bool *done) ++static CURLcode oldap_connecting(struct connectdata *conn, bool *done) + { + struct ldapconninfo *li = conn->proto.ldapc; + struct Curl_easy *data = conn->data; +@@ -349,13 +349,13 @@ static CURLcode ldap_connecting(struct connectdata *conn, bool *done) + + if(info) + ldap_memfree(info); +- conn->recv[FIRSTSOCKET] = ldap_recv; ++ conn->recv[FIRSTSOCKET] = oldap_recv; + *done = TRUE; + + return CURLE_OK; + } + +-static CURLcode ldap_disconnect(struct connectdata *conn, bool dead_connection) ++static CURLcode oldap_disconnect(struct connectdata *conn, bool dead_connection) + { + struct ldapconninfo *li = conn->proto.ldapc; + (void) dead_connection; +@@ -371,7 +371,7 @@ static CURLcode ldap_disconnect(struct connectdata *conn, bool dead_connection) + return CURLE_OK; + } + +-static CURLcode ldap_do(struct connectdata *conn, bool *done) ++static CURLcode oldap_do(struct connectdata *conn, bool *done) + { + struct ldapconninfo *li = conn->proto.ldapc; + ldapreqinfo *lr; +@@ -416,7 +416,7 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done) + return CURLE_OK; + } + +-static CURLcode ldap_done(struct connectdata *conn, CURLcode res, ++static CURLcode oldap_done(struct connectdata *conn, CURLcode res, + bool premature) + { + ldapreqinfo *lr = conn->data->req.protop; +@@ -438,7 +438,7 @@ static CURLcode ldap_done(struct connectdata *conn, CURLcode res, + return CURLE_OK; + } + +-static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf, ++static ssize_t oldap_recv(struct connectdata *conn, int sockindex, char *buf, + size_t len, CURLcode *err) + { + struct ldapconninfo *li = conn->proto.ldapc; diff --git a/debian/patches/0013-11-CVE-2023-27538.patch b/debian/patches/0013-11-CVE-2023-27538.patch new file mode 100644 index 0000000000000000000000000000000000000000..046a5fc5794b7beff8f4064cc594ab2543e180e8 --- /dev/null +++ b/debian/patches/0013-11-CVE-2023-27538.patch @@ -0,0 +1,22 @@ +From: zhaikangning <857458455@qq.com> +Date: Wed, 5 Jul 2023 08:57:41 +0000 +Subject: !11 CVE-2023-27538 Merge pull request !11 from + icehole/openkylin/yangtze + +--- + lib/url.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/url.c b/lib/url.c +index 01f7eda..7113b9a 100644 +--- a/lib/url.c ++++ b/lib/url.c +@@ -1233,7 +1233,7 @@ ConnectionExists(struct Curl_easy *data, + } + } + +- if(get_protocol_family(needle->handler->protocol) == PROTO_FAMILY_SSH) { ++ if(get_protocol_family(needle->handler->protocol) & PROTO_FAMILY_SSH) { + if(!ssh_config_matches(needle, check)) + continue; + } diff --git a/debian/patches/0013-36-CVE-2024-8096.patch b/debian/patches/0013-36-CVE-2024-8096.patch new file mode 100644 index 0000000000000000000000000000000000000000..5fdfc94e029c96b695961a140e25c64c1de3aa34 --- /dev/null +++ b/debian/patches/0013-36-CVE-2024-8096.patch @@ -0,0 +1,458 @@ +From: zhangtianxiong +Date: Tue, 31 Dec 2024 09:05:00 +0000 +Subject: =?utf-8?q?!36_=E5=AF=B9CVE-2024-8096=E7=9A=84=E4=BF=AE=E5=A4=8D_Me?= + =?utf-8?q?rge_pull_request_!36_from_zeng11/openkylin/yangtze?= + +--- + docs/examples/Makefile.am | 4 +- + lib/Makefile.am | 32 +++++----- + lib/curl_path.c | 71 +++++++++++----------- + lib/libcurl.vers.in | 2 +- + lib/vtls/gtls.c | 149 +++++++++++++++++++++++----------------------- + src/Makefile.am | 4 +- + tests/libtest/Makefile.am | 8 +-- + 7 files changed, 136 insertions(+), 134 deletions(-) + +diff --git a/docs/examples/Makefile.am b/docs/examples/Makefile.am +index 53867cb..254e72d 100644 +--- a/docs/examples/Makefile.am ++++ b/docs/examples/Makefile.am +@@ -48,9 +48,9 @@ LIBS = $(BLANK_AT_MAKETIME) + + # Dependencies + if USE_EXPLICIT_LIB_DEPS +-LDADD = $(LIBDIR)/libcurl.la @LIBCURL_LIBS@ ++LDADD = $(LIBDIR)/libcurl-nss.la @LIBCURL_LIBS@ + else +-LDADD = $(LIBDIR)/libcurl.la ++LDADD = $(LIBDIR)/libcurl-nss.la + endif + + # This might hold -Werror +diff --git a/lib/Makefile.am b/lib/Makefile.am +index 516a239..34940bf 100644 +--- a/lib/Makefile.am ++++ b/lib/Makefile.am +@@ -31,7 +31,7 @@ EXTRA_DIST = Makefile.m32 config-win32.h config-win32ce.h \ + config-tpf.h mk-ca-bundle.pl mk-ca-bundle.vbs $(CMAKE_DIST) \ + firefox-db2pem.sh config-vxworks.h Makefile.vxworks checksrc.pl + +-lib_LTLIBRARIES = libcurl.la ++lib_LTLIBRARIES = libcurl-nss.la + + if BUILD_UNITTESTS + noinst_LTLIBRARIES = libcurlu.la +@@ -83,43 +83,43 @@ AM_CPPFLAGS += -DBUILDING_LIBCURL + AM_LDFLAGS = + AM_CFLAGS = + +-libcurl_la_CPPFLAGS_EXTRA = +-libcurl_la_LDFLAGS_EXTRA = +-libcurl_la_CFLAGS_EXTRA = ++libcurl_nss_la_CPPFLAGS_EXTRA = ++libcurl_nss_la_LDFLAGS_EXTRA = ++libcurl_nss_la_CFLAGS_EXTRA = + + if CURL_LT_SHLIB_USE_VERSION_INFO +-libcurl_la_LDFLAGS_EXTRA += $(VERSIONINFO) ++libcurl_nss_la_LDFLAGS_EXTRA += $(VERSIONINFO) + endif + + if CURL_LT_SHLIB_USE_NO_UNDEFINED +-libcurl_la_LDFLAGS_EXTRA += -no-undefined ++libcurl_nss_la_LDFLAGS_EXTRA += -no-undefined + endif + + if CURL_LT_SHLIB_USE_MIMPURE_TEXT +-libcurl_la_LDFLAGS_EXTRA += -mimpure-text ++libcurl_nss_la_LDFLAGS_EXTRA += -mimpure-text + endif + + if CURL_LT_SHLIB_USE_VERSIONED_SYMBOLS +-libcurl_la_LDFLAGS_EXTRA += -Wl,--version-script=libcurl.vers ++libcurl_nss_la_LDFLAGS_EXTRA += -Wl,--version-script=libcurl.vers + else + # if symbol-hiding is enabled, hide them! + if DOING_CURL_SYMBOL_HIDING +-libcurl_la_LDFLAGS_EXTRA += -export-symbols-regex '^curl_.*' ++libcurl_nss_la_LDFLAGS_EXTRA += -export-symbols-regex '^curl_.*' + endif + endif + + if USE_CPPFLAG_CURL_STATICLIB +-libcurl_la_CPPFLAGS_EXTRA += -DCURL_STATICLIB ++libcurl_nss_la_CPPFLAGS_EXTRA += -DCURL_STATICLIB + endif + + if DOING_CURL_SYMBOL_HIDING +-libcurl_la_CPPFLAGS_EXTRA += -DCURL_HIDDEN_SYMBOLS +-libcurl_la_CFLAGS_EXTRA += $(CFLAG_CURL_SYMBOL_HIDING) ++libcurl_nss_la_CPPFLAGS_EXTRA += -DCURL_HIDDEN_SYMBOLS ++libcurl_nss_la_CFLAGS_EXTRA += $(CFLAG_CURL_SYMBOL_HIDING) + endif + +-libcurl_la_CPPFLAGS = $(AM_CPPFLAGS) $(libcurl_la_CPPFLAGS_EXTRA) +-libcurl_la_LDFLAGS = $(AM_LDFLAGS) $(libcurl_la_LDFLAGS_EXTRA) $(LDFLAGS) $(LIBCURL_LIBS) +-libcurl_la_CFLAGS = $(AM_CFLAGS) $(libcurl_la_CFLAGS_EXTRA) ++libcurl_nss_la_CPPFLAGS = $(AM_CPPFLAGS) $(libcurl_nss_la_CPPFLAGS_EXTRA) ++libcurl_nss_la_LDFLAGS = $(AM_LDFLAGS) $(libcurl_nss_la_LDFLAGS_EXTRA) $(LDFLAGS) $(LIBCURL_LIBS) ++libcurl_nss_la_CFLAGS = $(AM_CFLAGS) $(libcurl_nss_la_CFLAGS_EXTRA) + + libcurlu_la_CPPFLAGS = $(AM_CPPFLAGS) -DCURL_STATICLIB -DUNITTESTS + libcurlu_la_LDFLAGS = $(AM_LDFLAGS) -static $(LIBCURL_LIBS) +@@ -128,7 +128,7 @@ libcurlu_la_CFLAGS = $(AM_CFLAGS) + # Makefile.inc provides the CSOURCES and HHEADERS defines + include Makefile.inc + +-libcurl_la_SOURCES = $(CSOURCES) $(HHEADERS) ++libcurl_nss_la_SOURCES = $(CSOURCES) $(HHEADERS) + libcurlu_la_SOURCES = $(CSOURCES) $(HHEADERS) + + CHECKSRC = $(CS_$(V)) +diff --git a/lib/curl_path.c b/lib/curl_path.c +index 9936622..f429634 100644 +--- a/lib/curl_path.c ++++ b/lib/curl_path.c +@@ -30,8 +30,6 @@ + #include "escape.h" + #include "memdebug.h" + +- +-#define MAX_SSHPATH_LEN 100000 /* arbitrary */ + /* figure out the path to work with in this particular request */ + CURLcode Curl_getworkingpath(struct connectdata *conn, + char *homedir, /* when SFTP is used */ +@@ -39,57 +37,60 @@ CURLcode Curl_getworkingpath(struct connectdata *conn, + real path to work with */ + { + struct Curl_easy *data = conn->data; ++ char *real_path = NULL; + char *working_path; + size_t working_path_len; +- struct dynbuf npath; + CURLcode result = + Curl_urldecode(data, data->state.up.path, 0, &working_path, + &working_path_len, FALSE); + if(result) + return result; +-/* new path to switch to in case we need to */ +- Curl_dyn_init(&npath, MAX_SSHPATH_LEN); + + /* Check for /~/, indicating relative to the user's home directory */ +- if((data->conn->handler->protocol & CURLPROTO_SCP) && +- (working_path_len > 3) && (!memcmp(working_path, "/~/", 3))) { +- /* It is referenced to the home directory, so strip the leading '/~/' */ +- if(Curl_dyn_addn(&npath, &working_path[3], working_path_len - 3)) { ++ if(conn->handler->protocol & CURLPROTO_SCP) { ++ real_path = malloc(working_path_len + 1); ++ if(real_path == NULL) { + free(working_path); + return CURLE_OUT_OF_MEMORY; + } +- ++ if((working_path_len > 3) && (!memcmp(working_path, "/~/", 3))) ++ /* It is referenced to the home directory, so strip the leading '/~/' */ ++ memcpy(real_path, working_path + 3, working_path_len - 2); ++ else ++ memcpy(real_path, working_path, 1 + working_path_len); + } +- else if((data->conn->handler->protocol & CURLPROTO_SFTP) && +- (working_path_len > 2) && !memcmp(working_path, "/~/", 3)) { +- size_t len; +- const char *p; +- int copyfrom = 3; +- if(Curl_dyn_add(&npath, homedir)) { +- free(working_path); +- return CURLE_OUT_OF_MEMORY; ++ else if(conn->handler->protocol & CURLPROTO_SFTP) { ++ if((working_path_len > 1) && (working_path[1] == '~')) { ++ size_t homelen = strlen(homedir); ++ real_path = malloc(homelen + working_path_len + 1); ++ if(real_path == NULL) { ++ free(working_path); ++ return CURLE_OUT_OF_MEMORY; ++ } ++ /* It is referenced to the home directory, so strip the ++ leading '/' */ ++ memcpy(real_path, homedir, homelen); ++ real_path[homelen] = '/'; ++ real_path[homelen + 1] = '\0'; ++ if(working_path_len > 3) { ++ memcpy(real_path + homelen + 1, working_path + 3, ++ 1 + working_path_len -3); ++ } + } +- /* Copy a separating '/' if homedir does not end with one */ +- len = Curl_dyn_len(&npath); +- p = Curl_dyn_ptr(&npath); +- if(len && (p[len-1] != '/')) +- copyfrom = 2; +- +- if(Curl_dyn_addn(&npath, +- &working_path[copyfrom], working_path_len - copyfrom)) { +- free(working_path); +- return CURLE_OUT_OF_MEMORY; ++ else { ++ real_path = malloc(working_path_len + 1); ++ if(real_path == NULL) { ++ free(working_path); ++ return CURLE_OUT_OF_MEMORY; ++ } ++ memcpy(real_path, working_path, 1 + working_path_len); + } + } + +- if(Curl_dyn_len(&npath)) { +- free(working_path); ++ free(working_path); + +- /* store the pointer for the caller to receive */ +- *path = Curl_dyn_ptr(&npath); +- } +- else +- *path = working_path; ++ /* store the pointer for the caller to receive */ ++ *path = real_path; + + return CURLE_OK; + } +diff --git a/lib/libcurl.vers.in b/lib/libcurl.vers.in +index ae978a4..bce5633 100644 +--- a/lib/libcurl.vers.in ++++ b/lib/libcurl.vers.in +@@ -6,7 +6,7 @@ HIDDEN + _save*; + }; + +-CURL_@CURL_LT_SHLIB_VERSIONED_FLAVOUR@4 ++CURL_@CURL_LT_SHLIB_VERSIONED_FLAVOUR@3 + { + global: curl_*; + local: *; +diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c +index 92dbcd5..6e156ea 100644 +--- a/lib/vtls/gtls.c ++++ b/lib/vtls/gtls.c +@@ -672,6 +672,13 @@ gtls_connect_step1(struct connectdata *conn, + init_flags |= GNUTLS_NO_TICKETS; + #endif + ++#if defined(GNUTLS_NO_STATUS_REQUEST) ++ if(!config->verifystatus) ++ /* Disable the "status_request" TLS extension, enabled by default since ++ GnuTLS 3.8.0. */ ++ init_flags |= GNUTLS_NO_STATUS_REQUEST; ++#endif ++ + rc = gnutls_init(&BACKEND->session, init_flags); + if(rc != GNUTLS_E_SUCCESS) { + failf(data, "gnutls_init() failed: %d", rc); +@@ -1137,104 +1144,98 @@ gtls_connect_step3(struct connectdata *conn, + + #ifdef HAS_OCSP + if(SSL_CONN_CONFIG(verifystatus)) { +- if(gnutls_ocsp_status_request_is_checked(session, 0) == 0) { +- gnutls_datum_t status_request; +- gnutls_ocsp_resp_t ocsp_resp; +- +- gnutls_ocsp_cert_status_t status; +- gnutls_x509_crl_reason_t reason; +- +- rc = gnutls_ocsp_status_request_get(session, &status_request); +- +- infof(data, "\t server certificate status verification FAILED\n"); ++ gnutls_datum_t status_request; ++ gnutls_ocsp_resp_t ocsp_resp; ++ gnutls_ocsp_cert_status_t status; ++ gnutls_x509_crl_reason_t reason; ++ rc = gnutls_ocsp_status_request_get(session, &status_request); + + if(rc == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) { +- failf(data, "No OCSP response received"); +- return CURLE_SSL_INVALIDCERTSTATUS; +- } ++ failf(data, "No OCSP response received"); ++ return CURLE_SSL_INVALIDCERTSTATUS; ++ } + +- if(rc < 0) { +- failf(data, "Invalid OCSP response received"); +- return CURLE_SSL_INVALIDCERTSTATUS; +- } ++ if(rc < 0) { ++ failf(data, "Invalid OCSP response received"); ++ return CURLE_SSL_INVALIDCERTSTATUS; ++ } + + gnutls_ocsp_resp_init(&ocsp_resp); + +- rc = gnutls_ocsp_resp_import(ocsp_resp, &status_request); +- if(rc < 0) { +- failf(data, "Invalid OCSP response received"); +- return CURLE_SSL_INVALIDCERTSTATUS; +- } ++ rc = gnutls_ocsp_resp_import(ocsp_resp, &status_request); ++ if(rc < 0) { ++ failf(data, "Invalid OCSP response received"); ++ return CURLE_SSL_INVALIDCERTSTATUS; ++ } + + (void)gnutls_ocsp_resp_get_single(ocsp_resp, 0, NULL, NULL, NULL, NULL, +- &status, NULL, NULL, NULL, &reason); ++ &status, NULL, NULL, NULL, &reason); + +- switch(status) { +- case GNUTLS_OCSP_CERT_GOOD: +- break; ++ switch(status) { ++ case GNUTLS_OCSP_CERT_GOOD: ++ break; + + case GNUTLS_OCSP_CERT_REVOKED: { +- const char *crl_reason; +- +- switch(reason) { +- default: +- case GNUTLS_X509_CRLREASON_UNSPECIFIED: +- crl_reason = "unspecified reason"; +- break; +- +- case GNUTLS_X509_CRLREASON_KEYCOMPROMISE: +- crl_reason = "private key compromised"; +- break; +- +- case GNUTLS_X509_CRLREASON_CACOMPROMISE: +- crl_reason = "CA compromised"; +- break; ++ const char *crl_reason; + +- case GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED: +- crl_reason = "affiliation has changed"; +- break; +- +- case GNUTLS_X509_CRLREASON_SUPERSEDED: +- crl_reason = "certificate superseded"; +- break; +- +- case GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION: +- crl_reason = "operation has ceased"; +- break; ++ switch(reason) { ++ default: ++ case GNUTLS_X509_CRLREASON_UNSPECIFIED: ++ crl_reason = "unspecified reason"; ++ break; + +- case GNUTLS_X509_CRLREASON_CERTIFICATEHOLD: +- crl_reason = "certificate is on hold"; +- break; ++ case GNUTLS_X509_CRLREASON_KEYCOMPROMISE: ++ crl_reason = "private key compromised"; ++ break; ++ ++ case GNUTLS_X509_CRLREASON_CACOMPROMISE: ++ crl_reason = "CA compromised"; ++ break; ++ + +- case GNUTLS_X509_CRLREASON_REMOVEFROMCRL: +- crl_reason = "will be removed from delta CRL"; +- break; ++ case GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED: ++ crl_reason = "affiliation has changed"; ++ break; ++ ++ case GNUTLS_X509_CRLREASON_SUPERSEDED: ++ crl_reason = "certificate superseded"; ++ break; ++ ++ case GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION: ++ crl_reason = "operation has ceased"; ++ break; + +- case GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN: +- crl_reason = "privilege withdrawn"; +- break; ++ case GNUTLS_X509_CRLREASON_CERTIFICATEHOLD: ++ crl_reason = "certificate is on hold"; ++ break; + +- case GNUTLS_X509_CRLREASON_AACOMPROMISE: +- crl_reason = "AA compromised"; +- break; +- } ++ case GNUTLS_X509_CRLREASON_REMOVEFROMCRL: ++ crl_reason = "will be removed from delta CRL"; ++ break; + +- failf(data, "Server certificate was revoked: %s", crl_reason); ++ case GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN: ++ crl_reason = "privilege withdrawn"; + break; +- } ++ + +- default: +- case GNUTLS_OCSP_CERT_UNKNOWN: +- failf(data, "Server certificate status is unknown"); ++ case GNUTLS_X509_CRLREASON_AACOMPROMISE: ++ crl_reason = "AA compromised"; + break; + } + +- gnutls_ocsp_resp_deinit(ocsp_resp); ++ failf(data, "Server certificate was revoked: %s", crl_reason); ++ break; ++ } + +- return CURLE_SSL_INVALIDCERTSTATUS; ++ default: ++ case GNUTLS_OCSP_CERT_UNKNOWN: ++ failf(data, "Server certificate status is unknown"); ++ break; + } +- else +- infof(data, "\t server certificate status verification OK\n"); ++ ++ gnutls_ocsp_resp_deinit(ocsp_resp); ++ if(status != GNUTLS_OCSP_CERT_GOOD) ++ return CURLE_SSL_INVALIDCERTSTATUS; + } + else + infof(data, "\t server certificate status verification SKIPPED\n"); +diff --git a/src/Makefile.am b/src/Makefile.am +index 90f1562..fe14b72 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -61,9 +61,9 @@ CFLAGS += @CURL_CFLAG_EXTRAS@ + LIBS = $(BLANK_AT_MAKETIME) + + if USE_EXPLICIT_LIB_DEPS +-curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @LIBCURL_LIBS@ ++curl_LDADD = $(top_builddir)/lib/libcurl-nss.la @LIBMETALINK_LIBS@ @LIBCURL_LIBS@ + else +-curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @NSS_LIBS@ @SSL_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@ ++curl_LDADD = $(top_builddir)/lib/libcurl-nss.la @LIBMETALINK_LIBS@ @NSS_LIBS@ @SSL_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@ + endif + + curl_LDFLAGS = @LIBMETALINK_LDFLAGS@ +diff --git a/tests/libtest/Makefile.am b/tests/libtest/Makefile.am +index ca7c01c..f56c2c1 100644 +--- a/tests/libtest/Makefile.am ++++ b/tests/libtest/Makefile.am +@@ -57,11 +57,11 @@ CLEANFILES = lib1521.c + LIBS = $(BLANK_AT_MAKETIME) + + if USE_EXPLICIT_LIB_DEPS +-SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@ +-TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@ ++SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl-nss.la @LIBCURL_LIBS@ ++TESTUTIL_LIBS = $(top_builddir)/lib/libcurl-nss.la @LIBCURL_LIBS@ + else +-SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_LIBS@ @NSS_LIBS@ +-TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_AND_TIME_LIBS@ @NSS_LIBS@ ++SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl-nss.la @CURL_NETWORK_LIBS@ @NSS_LIBS@ ++TESTUTIL_LIBS = $(top_builddir)/lib/libcurl-nss.la @CURL_NETWORK_AND_TIME_LIBS@ @NSS_LIBS@ + endif + + # Dependencies (may need to be overridden) diff --git a/debian/patches/0014-32.patch b/debian/patches/0014-32.patch new file mode 100644 index 0000000000000000000000000000000000000000..8e4f5339dd23afea27b2b65a328561cae022cdab --- /dev/null +++ b/debian/patches/0014-32.patch @@ -0,0 +1,365 @@ +From: zhaikangning <857458455@qq.com> +Date: Mon, 18 Sep 2023 03:17:28 +0000 +Subject: =?utf-8?b?ITMyIOabtOaWsOeJiOacrOWPtyBNZXJnZSBwdWxsIHJlcXVlc3QgITMy?= + =?utf-8?b?IGZyb20gemhhaWthbmduaW5nL29wZW5reWxpbi95YW5ndHpl?= + +--- + lib/content_encoding.c | 7 +-- + lib/curl_path.c | 71 +++++++++++----------- + lib/url.c | 6 ++ + lib/urldata.h | 2 + + tests/data/Makefile.inc | 2 +- + tests/data/test418 | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ + 6 files changed, 202 insertions(+), 41 deletions(-) + create mode 100644 tests/data/test418 + +diff --git a/lib/content_encoding.c b/lib/content_encoding.c +index e646f31..fd0ca8a 100644 +--- a/lib/content_encoding.c ++++ b/lib/content_encoding.c +@@ -944,7 +944,6 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn, + { + struct Curl_easy *data = conn->data; + struct SingleRequest *k = &data->req; +- int counter = 0; + + do { + const char *name; +@@ -979,9 +978,9 @@ CURLcode Curl_build_unencoding_stack(struct connectdata *conn, + if(!encoding) + encoding = &error_encoding; /* Defer error at stack use. */ + +- if(++counter >= MAX_ENCODE_STACK) { +- failf(data, "Reject response due to %u content encodings", +- counter); ++ if(k->writer_stack_depth++ >= MAX_ENCODE_STACK) { ++ failf(data, "Reject response due to more than %u content encodings", ++ MAX_ENCODE_STACK); + return CURLE_BAD_CONTENT_ENCODING; + } + /* Stack the unencoding stage. */ +diff --git a/lib/curl_path.c b/lib/curl_path.c +index f429634..9936622 100644 +--- a/lib/curl_path.c ++++ b/lib/curl_path.c +@@ -30,6 +30,8 @@ + #include "escape.h" + #include "memdebug.h" + ++ ++#define MAX_SSHPATH_LEN 100000 /* arbitrary */ + /* figure out the path to work with in this particular request */ + CURLcode Curl_getworkingpath(struct connectdata *conn, + char *homedir, /* when SFTP is used */ +@@ -37,60 +39,57 @@ CURLcode Curl_getworkingpath(struct connectdata *conn, + real path to work with */ + { + struct Curl_easy *data = conn->data; +- char *real_path = NULL; + char *working_path; + size_t working_path_len; ++ struct dynbuf npath; + CURLcode result = + Curl_urldecode(data, data->state.up.path, 0, &working_path, + &working_path_len, FALSE); + if(result) + return result; ++/* new path to switch to in case we need to */ ++ Curl_dyn_init(&npath, MAX_SSHPATH_LEN); + + /* Check for /~/, indicating relative to the user's home directory */ +- if(conn->handler->protocol & CURLPROTO_SCP) { +- real_path = malloc(working_path_len + 1); +- if(real_path == NULL) { ++ if((data->conn->handler->protocol & CURLPROTO_SCP) && ++ (working_path_len > 3) && (!memcmp(working_path, "/~/", 3))) { ++ /* It is referenced to the home directory, so strip the leading '/~/' */ ++ if(Curl_dyn_addn(&npath, &working_path[3], working_path_len - 3)) { + free(working_path); + return CURLE_OUT_OF_MEMORY; + } +- if((working_path_len > 3) && (!memcmp(working_path, "/~/", 3))) +- /* It is referenced to the home directory, so strip the leading '/~/' */ +- memcpy(real_path, working_path + 3, working_path_len - 2); +- else +- memcpy(real_path, working_path, 1 + working_path_len); ++ + } +- else if(conn->handler->protocol & CURLPROTO_SFTP) { +- if((working_path_len > 1) && (working_path[1] == '~')) { +- size_t homelen = strlen(homedir); +- real_path = malloc(homelen + working_path_len + 1); +- if(real_path == NULL) { +- free(working_path); +- return CURLE_OUT_OF_MEMORY; +- } +- /* It is referenced to the home directory, so strip the +- leading '/' */ +- memcpy(real_path, homedir, homelen); +- real_path[homelen] = '/'; +- real_path[homelen + 1] = '\0'; +- if(working_path_len > 3) { +- memcpy(real_path + homelen + 1, working_path + 3, +- 1 + working_path_len -3); +- } ++ else if((data->conn->handler->protocol & CURLPROTO_SFTP) && ++ (working_path_len > 2) && !memcmp(working_path, "/~/", 3)) { ++ size_t len; ++ const char *p; ++ int copyfrom = 3; ++ if(Curl_dyn_add(&npath, homedir)) { ++ free(working_path); ++ return CURLE_OUT_OF_MEMORY; + } +- else { +- real_path = malloc(working_path_len + 1); +- if(real_path == NULL) { +- free(working_path); +- return CURLE_OUT_OF_MEMORY; +- } +- memcpy(real_path, working_path, 1 + working_path_len); ++ /* Copy a separating '/' if homedir does not end with one */ ++ len = Curl_dyn_len(&npath); ++ p = Curl_dyn_ptr(&npath); ++ if(len && (p[len-1] != '/')) ++ copyfrom = 2; ++ ++ if(Curl_dyn_addn(&npath, ++ &working_path[copyfrom], working_path_len - copyfrom)) { ++ free(working_path); ++ return CURLE_OUT_OF_MEMORY; + } + } + +- free(working_path); ++ if(Curl_dyn_len(&npath)) { ++ free(working_path); + +- /* store the pointer for the caller to receive */ +- *path = real_path; ++ /* store the pointer for the caller to receive */ ++ *path = Curl_dyn_ptr(&npath); ++ } ++ else ++ *path = working_path; + + return CURLE_OK; + } +diff --git a/lib/url.c b/lib/url.c +index 7113b9a..dca9168 100644 +--- a/lib/url.c ++++ b/lib/url.c +@@ -1233,6 +1233,11 @@ ConnectionExists(struct Curl_easy *data, + } + } + ++ /* GSS delegation differences do not actually affect every connection ++ and auth method, but this check takes precaution before efficiency */ ++ if(needle->gssapi_delegation != check->gssapi_delegation) ++ continue; ++ + if(get_protocol_family(needle->handler->protocol) & PROTO_FAMILY_SSH) { + if(!ssh_config_matches(needle, check)) + continue; +@@ -1659,6 +1664,7 @@ static struct connectdata *allocate_conn(struct Curl_easy *data) + conn->fclosesocket = data->set.fclosesocket; + conn->closesocket_client = data->set.closesocket_client; + conn->lastused = Curl_now(); /* used now */ ++ conn->gssapi_delegation = data->set.gssapi_delegation; + + return conn; + error: +diff --git a/lib/urldata.h b/lib/urldata.h +index 8f3c31d..380720c 100644 +--- a/lib/urldata.h ++++ b/lib/urldata.h +@@ -643,6 +643,7 @@ struct SingleRequest { + #ifndef CURL_DISABLE_DOH + struct dohdata doh; /* DoH specific data for this request */ + #endif ++ unsigned char writer_stack_depth; /* Unencoding stack depth. */ + BIT(header); /* incoming data has HTTP header */ + BIT(content_range); /* set TRUE if Content-Range: was found */ + BIT(upload_done); /* set to TRUE when doing chunked transfer-encoding +@@ -1071,6 +1072,7 @@ struct connectdata { + struct http_connect_state *connect_state; /* for HTTP CONNECT */ + struct connectbundle *bundle; /* The bundle we are member of */ + int negnpn; /* APLN or NPN TLS negotiated protocol, CURL_HTTP_VERSION* */ ++ unsigned char gssapi_delegation; /* inherited from set.gssapi_delegation */ + + #ifdef USE_UNIX_SOCKETS + char *unix_domain_socket; +diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc +index 52bdaec..c005d5f 100644 +--- a/tests/data/Makefile.inc ++++ b/tests/data/Makefile.inc +@@ -63,7 +63,7 @@ test350 test351 test352 test353 test354 test355 test356 \ + test393 test394 test395 \ + \ + test400 test401 test402 test403 test404 test405 test406 test407 test408 \ +-test409 \ ++test409 test418 \ + \ + test490 test491 test492 \ + \ +diff --git a/tests/data/test418 b/tests/data/test418 +new file mode 100644 +index 0000000..6035e3f +--- /dev/null ++++ b/tests/data/test418 +@@ -0,0 +1,155 @@ ++ ++ ++ ++HTTP ++gzip ++ ++ ++ ++# ++# Server-side ++ ++ ++HTTP/1.1 200 OK ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++Transfer-Encoding: gzip ++ ++-foo- ++ ++ ++ ++# ++# Client-side ++ ++ ++http ++ ++ ++Response with multiple Transfer-Encoding headers ++ ++ ++http://%HOSTIP:%HTTPPORT/418 -sS ++ ++ ++ ++# ++# Verify data after the test has been "shot" ++ ++ ++^User-Agent: curl/.* ++ ++ ++GET /418 HTTP/1.1 ++Host: %HOSTIP:%HTTPPORT ++User-Agent: curl/7.68.0 ++Accept: */* ++ ++ ++ ++# CURLE_BAD_CONTENT_ENCODING is 61 ++ ++61 ++ ++ ++curl: (61) Reject response due to more than 5 content encodings ++ ++ ++ diff --git a/debian/patches/0014-38-CVE-2023-28322.patch b/debian/patches/0014-38-CVE-2023-28322.patch new file mode 100644 index 0000000000000000000000000000000000000000..81169fea099277eb0f7455192b08fd81532d0bfb --- /dev/null +++ b/debian/patches/0014-38-CVE-2023-28322.patch @@ -0,0 +1,169 @@ +From: zhangtianxiong +Date: Tue, 31 Dec 2024 09:05:51 +0000 +Subject: =?utf-8?q?!38_=E4=BF=AE=E8=A1=A5CVE-2023-28322_Merge_pull_request_?= + =?utf-8?q?!38_from_Mr=2EAgony/openkylin/yangtze?= + +--- + lib/curl_rtmp.c | 4 ++-- + lib/file.c | 4 ++-- + lib/ftp.c | 6 +++--- + lib/http.c | 4 ++-- + lib/imap.c | 8 ++++---- + lib/rtsp.c | 4 ++-- + 6 files changed, 15 insertions(+), 15 deletions(-) + +diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c +index df8f2b1..51c58b8 100644 +--- a/lib/curl_rtmp.c ++++ b/lib/curl_rtmp.c +@@ -213,7 +213,7 @@ static CURLcode rtmp_connect(struct connectdata *conn, bool *done) + /* We have to know if it's a write before we send the + * connect request packet + */ +- if(conn->data->set.upload) ++ if(conn->data->state.upload) + r->Link.protocol |= RTMP_FEATURE_WRITE; + + /* For plain streams, use the buffer toggle trick to keep data flowing */ +@@ -245,7 +245,7 @@ static CURLcode rtmp_do(struct connectdata *conn, bool *done) + if(!RTMP_ConnectStream(r, 0)) + return CURLE_FAILED_INIT; + +- if(conn->data->set.upload) { ++ if(conn->data->state.upload) { + Curl_pgrsSetUploadSize(data, data->state.infilesize); + Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET); + } +diff --git a/lib/file.c b/lib/file.c +index 2492370..b7dc64a 100644 +--- a/lib/file.c ++++ b/lib/file.c +@@ -198,7 +198,7 @@ static CURLcode file_connect(struct connectdata *conn, bool *done) + file->freepath = real_path; /* free this when done */ + + file->fd = fd; +- if(!data->set.upload && (fd == -1)) { ++ if(!data->state.upload && (fd == -1)) { + failf(data, "Couldn't open file %s", data->state.up.path); + file_done(conn, CURLE_FILE_COULDNT_READ_FILE, FALSE); + return CURLE_FILE_COULDNT_READ_FILE; +@@ -390,7 +390,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done) + + Curl_pgrsStartNow(data); + +- if(data->set.upload) ++ if(data->state.upload) + return file_upload(conn); + + file = conn->data->req.protop; +diff --git a/lib/ftp.c b/lib/ftp.c +index 688c11e..f68eb4b 100644 +--- a/lib/ftp.c ++++ b/lib/ftp.c +@@ -3303,7 +3303,7 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status, + /* the response code from the transfer showed an error already so no + use checking further */ + ; +- else if(data->set.upload) { ++ else if(data->state.upload) { + if((-1 != data->state.infilesize) && + (data->state.infilesize != data->req.writebytecount) && + !data->set.crlf && +@@ -3570,7 +3570,7 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep) + connected back to us */ + } + } +- else if(data->set.upload) { ++ else if(data->state.upload) { + result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_STOR_TYPE); + if(result) + return result; +@@ -4205,7 +4205,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn) + ftpc->file = NULL; /* instead of point to a zero byte, + we make it a NULL pointer */ + +- if(data->set.upload && !ftpc->file && (ftp->transfer == FTPTRANSFER_BODY)) { ++ if(data->state.upload && !ftpc->file && (ftp->transfer == FTPTRANSFER_BODY)) { + /* We need a file name when uploading. Return error! */ + failf(data, "Uploading to a URL without a file name!"); + free(rawPath); +diff --git a/lib/http.c b/lib/http.c +index 4d6626b..7df7f7d 100644 +--- a/lib/http.c ++++ b/lib/http.c +@@ -2080,7 +2080,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) + } + + if((conn->handler->protocol&(PROTO_FAMILY_HTTP|CURLPROTO_FTP)) && +- data->set.upload) { ++ data->state.upload) { + httpreq = HTTPREQ_PUT; + } + +@@ -2261,7 +2261,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done) + if((conn->handler->protocol & PROTO_FAMILY_HTTP) && + (((httpreq == HTTPREQ_POST_MIME || httpreq == HTTPREQ_POST_FORM) && + http->postsize < 0) || +- ((data->set.upload || httpreq == HTTPREQ_POST) && ++ ((data->state.upload || httpreq == HTTPREQ_POST) && + data->state.infilesize == -1))) { + if(conn->bits.authneg) + /* don't enable chunked during auth neg */ +diff --git a/lib/imap.c b/lib/imap.c +index 0ca700f..eff20d1 100644 +--- a/lib/imap.c ++++ b/lib/imap.c +@@ -111,7 +111,7 @@ static CURLcode imap_continue_authenticate(struct connectdata *conn, + static void imap_get_message(char *buffer, char **outptr); + + /* +- * IMAP protocol handler. ++ * IMAP protocol handler.upload + */ + + const struct Curl_handler Curl_handler_imap = { +@@ -1469,11 +1469,11 @@ static CURLcode imap_done(struct connectdata *conn, CURLcode status, + result = status; /* use the already set error code */ + } + else if(!data->set.connect_only && !imap->custom && +- (imap->uid || imap->mindex || data->set.upload || ++ (imap->uid || imap->mindex || data->state.upload || + data->set.mimepost.kind != MIMEKIND_NONE)) { + /* Handle responses after FETCH or APPEND transfer has finished */ + +- if(!data->set.upload && data->set.mimepost.kind == MIMEKIND_NONE) ++ if(!data->state.upload && data->set.mimepost.kind == MIMEKIND_NONE) + state(conn, IMAP_FETCH_FINAL); + else { + /* End the APPEND command first by sending an empty line */ +@@ -1539,7 +1539,7 @@ static CURLcode imap_perform(struct connectdata *conn, bool *connected, + selected = TRUE; + + /* Start the first command in the DO phase */ +- if(conn->data->set.upload || data->set.mimepost.kind != MIMEKIND_NONE) ++ if(conn->data->state.upload || data->set.mimepost.kind != MIMEKIND_NONE) + /* APPEND can be executed directly */ + result = imap_perform_append(conn); + else if(imap->custom && (selected || !imap->mailbox)) +diff --git a/lib/rtsp.c b/lib/rtsp.c +index bba4c16..0a2c85d 100644 +--- a/lib/rtsp.c ++++ b/lib/rtsp.c +@@ -499,7 +499,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done) + rtspreq == RTSPREQ_SET_PARAMETER || + rtspreq == RTSPREQ_GET_PARAMETER) { + +- if(data->set.upload) { ++ if(data->state.upload) { + putsize = data->state.infilesize; + data->set.httpreq = HTTPREQ_PUT; + +@@ -518,7 +518,7 @@ static CURLcode rtsp_do(struct connectdata *conn, bool *done) + result = + Curl_add_bufferf(&req_buffer, + "Content-Length: %" CURL_FORMAT_CURL_OFF_T"\r\n", +- (data->set.upload ? putsize : postsize)); ++ (data->state.upload ? putsize : postsize)); + if(result) + return result; + } diff --git a/debian/patches/0015-43-CVE-2023-27533-telnet-only-accept-option-argument.patch b/debian/patches/0015-43-CVE-2023-27533-telnet-only-accept-option-argument.patch new file mode 100644 index 0000000000000000000000000000000000000000..58b4f73afd8034f2373d5094f92c8e820d8a74ba --- /dev/null +++ b/debian/patches/0015-43-CVE-2023-27533-telnet-only-accept-option-argument.patch @@ -0,0 +1,50 @@ +From: =?utf-8?b?6YKT5omY?= +Date: Fri, 9 Jan 2026 06:47:55 +0000 +Subject: =?utf-8?q?!43_CVE-2023-27533_=E5=AE=89=E5=85=A8=E6=9B=B4=E6=96=B0?= + =?utf-8?q?=3A_telnet=3A_only_accept_option_arguments_in_ascii_Merge_pull_r?= + =?utf-8?q?equest_!43_from_Tooooa/openkylin/yangtze?= + +--- + lib/telnet.c | 15 +++++++++++++++ + 1 file changed, 15 insertions(+) + +diff --git a/lib/telnet.c b/lib/telnet.c +index f585bce..1c2c8d6 100644 +--- a/lib/telnet.c ++++ b/lib/telnet.c +@@ -815,6 +815,17 @@ static void printsub(struct Curl_easy *data, + } + } + ++static bool str_is_nonascii(const char *str) ++{ ++ size_t len = strlen(str); ++ while(len--) { ++ if(*str & 0x80) ++ return TRUE; ++ str++; ++ } ++ return FALSE; ++} ++ + static CURLcode check_telnet_options(struct connectdata *conn) + { + struct curl_slist *head; +@@ -829,6 +840,8 @@ static CURLcode check_telnet_options(struct connectdata *conn) + /* Add the user name as an environment variable if it + was given on the command line */ + if(conn->bits.user_passwd) { ++ if(str_is_nonascii(conn->user)) ++ return CURLE_BAD_FUNCTION_ARGUMENT; + msnprintf(option_arg, sizeof(option_arg), "USER,%s", conn->user); + beg = curl_slist_append(tn->telnet_vars, option_arg); + if(!beg) { +@@ -843,6 +856,8 @@ static CURLcode check_telnet_options(struct connectdata *conn) + for(head = data->set.telnet_options; head; head = head->next) { + if(sscanf(head->data, "%127[^= ]%*[ =]%255s", + option_keyword, option_arg) == 2) { ++ if(str_is_nonascii(option_arg)) ++ continue; + + /* Terminal type */ + if(strcasecompare(option_keyword, "TTYPE")) { diff --git a/debian/patches/0016-48-CVE-2023-46218-Fix-Cookie-mixed-case-PSL-bypass.patch b/debian/patches/0016-48-CVE-2023-46218-Fix-Cookie-mixed-case-PSL-bypass.patch new file mode 100644 index 0000000000000000000000000000000000000000..27b1df99844645ab35b11e16d25b34423bf27672 --- /dev/null +++ b/debian/patches/0016-48-CVE-2023-46218-Fix-Cookie-mixed-case-PSL-bypass.patch @@ -0,0 +1,46 @@ +From: =?utf-8?b?6YKT5omY?= +Date: Fri, 9 Jan 2026 06:50:41 +0000 +Subject: !48 CVE-2023-46218 Fix: Cookie mixed case PSL bypass Merge pull + request !48 from yulin_pro/openkylin/yangtze + +--- + lib/cookie.c | 25 ++++++++++++++++--------- + 1 file changed, 16 insertions(+), 9 deletions(-) + +diff --git a/lib/cookie.c b/lib/cookie.c +index 76b6206..27156ee 100644 +--- a/lib/cookie.c ++++ b/lib/cookie.c +@@ -972,16 +972,23 @@ Curl_cookie_add(struct Curl_easy *data, + #ifdef USE_LIBPSL + /* Check if the domain is a Public Suffix and if yes, ignore the cookie. */ + if(domain && co->domain && !isip(co->domain)) { +- const psl_ctx_t *psl = Curl_psl_use(data); +- int acceptable; +- +- if(psl) { +- acceptable = psl_is_cookie_domain_acceptable(psl, domain, co->domain); +- Curl_psl_release(data); ++ bool acceptable = FALSE; ++ char lcase[256]; ++ char lcookie[256]; ++ size_t dlen = strlen(domain); ++ size_t clen = strlen(co->domain); ++ if((dlen < sizeof(lcase)) && (clen < sizeof(lcookie))){ ++ const psl_ctx_t *psl = Curl_psl_use(data); ++ if(psl){ ++ /* the PSL check requires lowercase domain name and pattern */ ++ Curl_strntolower(lcase,domain,dlen + 1); ++ Curl_strntolower(lcookie,co->domain,clen + 1); ++ acceptable = psl_is_cookie_domain_acceptable(psl,lcase,lcookie); ++ Curl_psl_release(data); ++ } ++ else ++ acceptable = !bad_domain(domain); + } +- else +- acceptable = !bad_domain(domain); +- + if(!acceptable) { + infof(data, "cookie '%s' dropped, domain '%s' must not " + "set cookies for '%s'\n", co->name, domain, co->domain); diff --git a/debian/patches/0017-53-fix-lib-fix-integer-overflow-in-gzip-header-parsi.patch b/debian/patches/0017-53-fix-lib-fix-integer-overflow-in-gzip-header-parsi.patch new file mode 100644 index 0000000000000000000000000000000000000000..01e81ef82f9fcdb56fd19e3f7edd7e8d8f0ed18c --- /dev/null +++ b/debian/patches/0017-53-fix-lib-fix-integer-overflow-in-gzip-header-parsi.patch @@ -0,0 +1,23 @@ +From: =?utf-8?b?6YKT5omY?= +Date: Fri, 9 Jan 2026 06:51:56 +0000 +Subject: !53 fix(lib): fix integer overflow in gzip header parsing + (CVE-2025-0725) Merge pull request !53 from naniy/fix-cve-2025-0725 + +--- + lib/content_encoding.c | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/lib/content_encoding.c b/lib/content_encoding.c +index fd0ca8a..23e9cab 100644 +--- a/lib/content_encoding.c ++++ b/lib/content_encoding.c +@@ -506,6 +506,9 @@ static CURLcode gzip_unencode_write(struct connectdata *conn, + { + /* Need more gzip header data state */ + ssize_t hlen; ++ if(nbytes > (uInt)-1 - z->avail_in) { ++ return exit_zlib(conn, z, &zp->zlib_init, CURLE_OUT_OF_MEMORY); ++ } + z->avail_in += (uInt) nbytes; + z->next_in = Curl_saferealloc(z->next_in, z->avail_in); + if(z->next_in == NULL) { diff --git a/debian/patches/0018-45-Fix-CVE-2025-0725-Gzip-integer-overflow-with-old-.patch b/debian/patches/0018-45-Fix-CVE-2025-0725-Gzip-integer-overflow-with-old-.patch new file mode 100644 index 0000000000000000000000000000000000000000..59cf2df9cdd4098998676fbf57b8ce0f46413134 --- /dev/null +++ b/debian/patches/0018-45-Fix-CVE-2025-0725-Gzip-integer-overflow-with-old-.patch @@ -0,0 +1,34 @@ +From: =?utf-8?b?6YKT5omY?= +Date: Fri, 9 Jan 2026 06:55:04 +0000 +Subject: !45 Fix: CVE-2025-0725 - Gzip integer overflow with old zlib Merge + pull request !45 from Elian/openkylin/yangtze + +--- + lib/content_encoding.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/lib/content_encoding.c b/lib/content_encoding.c +index 23e9cab..84ba409 100644 +--- a/lib/content_encoding.c ++++ b/lib/content_encoding.c +@@ -327,7 +327,11 @@ static CURLcode gzip_init_writer(struct connectdata *conn, + /* Initialize zlib */ + z->zalloc = (alloc_func) zalloc_cb; + z->zfree = (free_func) zfree_cb; +- ++ /* Fix: CVE-2025-0725 - reject too old zlib versions */ ++ if(strncmp(zlibVersion(), "1.2.0.4", 7) < 0) { ++ failf(conn->data, "zlib version too old (CVE-2025-0725)"); ++ return CURLE_FAILED_INIT; ++ } + if(strcmp(zlibVersion(), "1.2.0.4") >= 0) { + /* zlib ver. >= 1.2.0.4 supports transparent gzip decompressing */ + if(inflateInit2(z, MAX_WBITS + 32) != Z_OK) { +@@ -335,6 +339,7 @@ static CURLcode gzip_init_writer(struct connectdata *conn, + } + zp->zlib_init = ZLIB_INIT_GZIP; /* Transparent gzip decompress state */ + } ++ + else { + /* we must parse the gzip header and trailer ourselves */ + if(inflateInit2(z, -MAX_WBITS) != Z_OK) { diff --git a/debian/patches/0019-46-CVE-2023-38545-FIX.patch b/debian/patches/0019-46-CVE-2023-38545-FIX.patch new file mode 100644 index 0000000000000000000000000000000000000000..5acbc2293554e8f40018b0399b25c8efbd759740 --- /dev/null +++ b/debian/patches/0019-46-CVE-2023-38545-FIX.patch @@ -0,0 +1,35 @@ +From: =?utf-8?b?6YKT5omY?= +Date: Fri, 9 Jan 2026 07:00:03 +0000 +Subject: !46 CVE-2023-38545 FIX Merge pull request !46 from + harrisonls/openkylin/yangtze + +--- + lib/socks.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/lib/socks.c b/lib/socks.c +index 6ae9818..f08326d 100644 +--- a/lib/socks.c ++++ b/lib/socks.c +@@ -398,9 +398,9 @@ CURLcode Curl_SOCKS5(const char *proxy_user, + + /* RFC1928 chapter 5 specifies max 255 chars for domain name in packet */ + if(!socks5_resolve_local && hostname_len > 255) { +- infof(conn->data, "SOCKS5: server resolving disabled for hostnames of " +- "length > 255 [actual len=%zu]\n", hostname_len); +- socks5_resolve_local = TRUE; ++ failf(data, "SOCKS5: the destination hostname is too long to be " ++ "resolved remotely by the proxy."); ++ return CURLE_COULDNT_RESOLVE_HOST; + } + + /* get timeout */ +@@ -605,7 +605,7 @@ CURLcode Curl_SOCKS5(const char *proxy_user, + + if(!socks5_resolve_local) { + socksreq[len++] = 3; /* ATYP: domain name = 3 */ +- socksreq[len++] = (char) hostname_len; /* address length */ ++ socksreq[len++] = (unsigned char) hostname_len; /* address length */ + memcpy(&socksreq[len], hostname, hostname_len); /* address str w/o NULL */ + len += hostname_len; + msnprintf(dest, sizeof(dest), "%s:%d", hostname, remote_port); diff --git a/debian/patches/0020-50-curl-backport-CVE-2023-28321-IDN-wildcard-match-f.patch b/debian/patches/0020-50-curl-backport-CVE-2023-28321-IDN-wildcard-match-f.patch new file mode 100644 index 0000000000000000000000000000000000000000..eb1328e4bbb2b97040c60858f6159a5c5b5d8d8a --- /dev/null +++ b/debian/patches/0020-50-curl-backport-CVE-2023-28321-IDN-wildcard-match-f.patch @@ -0,0 +1,135 @@ +From: =?utf-8?b?6YKT5omY?= +Date: Fri, 9 Jan 2026 07:02:32 +0000 +Subject: !50 curl: backport CVE-2023-28321 IDN wildcard match fix Merge pull + request !50 from Susuyyy666/fix-CVE-2023-28321 + +--- + lib/hostcheck.c | 106 ++++++++++++++++++-------------------------------------- + 1 file changed, 34 insertions(+), 72 deletions(-) + +diff --git a/lib/hostcheck.c b/lib/hostcheck.c +index 9e0db05..7edf486 100644 +--- a/lib/hostcheck.c ++++ b/lib/hostcheck.c +@@ -42,87 +42,49 @@ + /* The last #include file should be: */ + #include "memdebug.h" + +-/* +- * Match a hostname against a wildcard pattern. +- * E.g. +- * "foo.host.com" matches "*.host.com". +- * +- * We use the matching rule described in RFC6125, section 6.4.3. +- * https://tools.ietf.org/html/rfc6125#section-6.4.3 +- * +- * In addition: ignore trailing dots in the host names and wildcards, so that +- * the names are used normalized. This is what the browsers do. +- * +- * Do not allow wildcard matching on IP numbers. There are apparently +- * certificates being used with an IP address in the CN field, thus making no +- * apparent distinction between a name and an IP. We need to detect the use of +- * an IP address and not wildcard match on such names. +- * +- * NOTE: hostmatch() gets called with copied buffers so that it can modify the +- * contents at will. +- */ + +-static int hostmatch(char *hostname, char *pattern) ++ ++static bool hostmatch(const char *hostname, ++ size_t hostlen, ++ const char *pattern, ++ size_t patternlen) + { +- const char *pattern_label_end, *pattern_wildcard, *hostname_label_end; +- int wildcard_enabled; +- size_t prefixlen, suffixlen; +- struct in_addr ignored; +-#ifdef ENABLE_IPV6 +- struct sockaddr_in6 si6; +-#endif ++ const char *pattern_label_end; ++ ++ DEBUGASSERT(pattern); ++ DEBUGASSERT(patternlen); ++ DEBUGASSERT(hostname); ++ DEBUGASSERT(hostlen); + + /* normalize pattern and hostname by stripping off trailing dots */ +- size_t len = strlen(hostname); +- if(hostname[len-1]=='.') +- hostname[len-1] = 0; +- len = strlen(pattern); +- if(pattern[len-1]=='.') +- pattern[len-1] = 0; +- +- pattern_wildcard = strchr(pattern, '*'); +- if(pattern_wildcard == NULL) +- return strcasecompare(pattern, hostname) ? +- CURL_HOST_MATCH : CURL_HOST_NOMATCH; ++ if(hostname[hostlen - 1] == '.') ++ hostlen--; ++ if(pattern[patternlen - 1] == '.') ++ patternlen--; ++ ++ if(strncmp(pattern, "*.", 2)) ++ return pmatch(hostname, hostlen, pattern, patternlen); + + /* detect IP address as hostname and fail the match if so */ +- if(Curl_inet_pton(AF_INET, hostname, &ignored) > 0) +- return CURL_HOST_NOMATCH; +-#ifdef ENABLE_IPV6 +- if(Curl_inet_pton(AF_INET6, hostname, &si6.sin6_addr) > 0) +- return CURL_HOST_NOMATCH; +-#endif ++ else if(Curl_host_is_ipnum(hostname)) ++ return FALSE; + +- /* We require at least 2 dots in pattern to avoid too wide wildcard ++ /* We require at least 2 dots in the pattern to avoid too wide wildcard + match. */ +- wildcard_enabled = 1; +- pattern_label_end = strchr(pattern, '.'); +- if(pattern_label_end == NULL || strchr(pattern_label_end + 1, '.') == NULL || +- pattern_wildcard > pattern_label_end || +- strncasecompare(pattern, "xn--", 4)) { +- wildcard_enabled = 0; ++ pattern_label_end = memchr(pattern, '.', patternlen); ++ if(!pattern_label_end || ++ (memrchr(pattern, '.', patternlen) == pattern_label_end)) ++ return pmatch(hostname, hostlen, pattern, patternlen); ++ else { ++ const char *hostname_label_end = memchr(hostname, '.', hostlen); ++ if(hostname_label_end) { ++ size_t skiphost = hostname_label_end - hostname; ++ size_t skiplen = pattern_label_end - pattern; ++ return pmatch(hostname_label_end, hostlen - skiphost, ++ pattern_label_end, patternlen - skiplen); ++ } + } +- if(!wildcard_enabled) +- return strcasecompare(pattern, hostname) ? +- CURL_HOST_MATCH : CURL_HOST_NOMATCH; +- +- hostname_label_end = strchr(hostname, '.'); +- if(hostname_label_end == NULL || +- !strcasecompare(pattern_label_end, hostname_label_end)) +- return CURL_HOST_NOMATCH; +- +- /* The wildcard must match at least one character, so the left-most +- label of the hostname is at least as large as the left-most label +- of the pattern. */ +- if(hostname_label_end - hostname < pattern_label_end - pattern) +- return CURL_HOST_NOMATCH; +- +- prefixlen = pattern_wildcard - pattern; +- suffixlen = pattern_label_end - (pattern_wildcard + 1); +- return strncasecompare(pattern, hostname, prefixlen) && +- strncasecompare(pattern_wildcard + 1, hostname_label_end - suffixlen, +- suffixlen) ? +- CURL_HOST_MATCH : CURL_HOST_NOMATCH; ++ return FALSE; + } + + int Curl_cert_hostcheck(const char *match_pattern, const char *hostname) diff --git a/debian/patches/0021-51-CVE-2024-8096-add-basic-safety-validation-to-stre.patch b/debian/patches/0021-51-CVE-2024-8096-add-basic-safety-validation-to-stre.patch new file mode 100644 index 0000000000000000000000000000000000000000..ec8f17e436ffb01b4eab323f5fc26ca5a08f3e5e --- /dev/null +++ b/debian/patches/0021-51-CVE-2024-8096-add-basic-safety-validation-to-stre.patch @@ -0,0 +1,23 @@ +From: =?utf-8?b?6YKT5omY?= +Date: Fri, 9 Jan 2026 07:04:53 +0000 +Subject: =?utf-8?q?!51_CVE-2024-8096=3A_add_basic_safety_validation_to_stre?= + =?utf-8?q?ngthen_hardening_Merge_pull_request_!51_from_=E7=99=BD=E9=93=B6?= + =?utf-8?q?=E5=AE=88=E5=BE=A1/openkylin/yangtze?= + +--- + lib/vtls/gtls.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c +index 6e156ea..c268eef 100644 +--- a/lib/vtls/gtls.c ++++ b/lib/vtls/gtls.c +@@ -673,7 +673,7 @@ gtls_connect_step1(struct connectdata *conn, + #endif + + #if defined(GNUTLS_NO_STATUS_REQUEST) +- if(!config->verifystatus) ++ if(!SSL_CONN_CONFIG(verifystatus)) + /* Disable the "status_request" TLS extension, enabled by default since + GnuTLS 3.8.0. */ + init_flags |= GNUTLS_NO_STATUS_REQUEST; diff --git a/debian/patches/0022-56-CVE-2023-28321-fix-host-name-wildcard-checking.patch b/debian/patches/0022-56-CVE-2023-28321-fix-host-name-wildcard-checking.patch new file mode 100644 index 0000000000000000000000000000000000000000..988057be13174b1f73bf0ef7adff47f6e43712ae --- /dev/null +++ b/debian/patches/0022-56-CVE-2023-28321-fix-host-name-wildcard-checking.patch @@ -0,0 +1,42 @@ +From: =?utf-8?b?6YKT5omY?= +Date: Wed, 14 Jan 2026 03:11:05 +0000 +Subject: =?utf-8?q?!56_CVE-2023-28321_=E5=AE=89=E5=85=A8=E6=9B=B4=E6=96=B0?= + =?utf-8?q?=EF=BC=9Afix_host_name_wildcard_checking_Merge_pull_request_!56_?= + =?utf-8?q?from_17726/openkylin/yangtze?= + +--- + lib/hostcheck.c | 19 ++++++++++++++----- + 1 file changed, 14 insertions(+), 5 deletions(-) + +diff --git a/lib/hostcheck.c b/lib/hostcheck.c +index 7edf486..0fc75d8 100644 +--- a/lib/hostcheck.c ++++ b/lib/hostcheck.c +@@ -62,13 +62,22 @@ static bool hostmatch(const char *hostname, + if(pattern[patternlen - 1] == '.') + patternlen--; + +- if(strncmp(pattern, "*.", 2)) ++ if(memchr(pattern, '*', patternlen)) { ++ /* Only match on "*" being used for the leftmost label */ ++ if(strncmp(pattern, "*.", 2)) ++ return FALSE; ++ ++ /* detect IP address as hostname and fail the match if so */ ++ if(Curl_host_is_ipnum(hostname)) ++ return FALSE; ++ ++ /* IDN A-labels starting with "xn--" must not match wildcards */ ++ if(strncasecompare(hostname, "xn--", 4)) ++ return FALSE; ++ } ++ else + return pmatch(hostname, hostlen, pattern, patternlen); + +- /* detect IP address as hostname and fail the match if so */ +- else if(Curl_host_is_ipnum(hostname)) +- return FALSE; +- + /* We require at least 2 dots in the pattern to avoid too wide wildcard + match. */ + pattern_label_end = memchr(pattern, '.', patternlen); diff --git a/debian/patches/0023-55-Fix-CVE-2021-22926-Secure-Transport-cert-name-fil.patch b/debian/patches/0023-55-Fix-CVE-2021-22926-Secure-Transport-cert-name-fil.patch new file mode 100644 index 0000000000000000000000000000000000000000..3c26f415f06100005ef5cf3f5443f18b8642c3cb --- /dev/null +++ b/debian/patches/0023-55-Fix-CVE-2021-22926-Secure-Transport-cert-name-fil.patch @@ -0,0 +1,58 @@ +From: Huafucius +Date: Sat, 7 Nov 2026 07:56:17 +0000 +Subject: !55 Fix CVE-2021-22926: Secure Transport cert name/file mix-up + +* Fix CVE-2021-22926: Secure Transport cert name/file mix-up +--- + lib/vtls/sectransp.c | 25 +++++++++++++------------ + 1 file changed, 13 insertions(+), 12 deletions(-) + +diff --git a/lib/vtls/sectransp.c b/lib/vtls/sectransp.c +index 1c05607..41cbff3 100644 +--- a/lib/vtls/sectransp.c ++++ b/lib/vtls/sectransp.c +@@ -32,6 +32,7 @@ + #include "curl_base64.h" + #include "strtok.h" + #include "multiif.h" ++#include "strcase.h" + + #ifdef USE_SECTRANSP + +@@ -1615,24 +1616,24 @@ static CURLcode sectransp_connect_step1(struct connectdata *conn, + SecIdentityRef cert_and_key = NULL; + bool is_cert_file = is_file(ssl_cert); + +- /* User wants to authenticate with a client cert. Look for it: +- If we detect that this is a file on disk, then let's load it. +- Otherwise, assume that the user wants to use an identity loaded +- from the Keychain. */ +- if(is_cert_file) { ++ /* User wants to authenticate with a client cert. Look for it. Assume that ++ the user wants to use an identity loaded from the Keychain. If not, try ++ it as a file on disk. */ ++ ++ err = CopyIdentityWithLabel(ssl_cert, &cert_and_key); ++ if((err != noErr) && is_cert_file) { + if(!SSL_SET_OPTION(cert_type)) +- infof(data, "WARNING: SSL: Certificate type not set, assuming " ++ infof(data, "SSL: Certificate type not set, assuming " + "PKCS#12 format.\n"); +- else if(strncmp(SSL_SET_OPTION(cert_type), "P12", +- strlen(SSL_SET_OPTION(cert_type))) != 0) +- infof(data, "WARNING: SSL: The Security framework only supports " +- "loading identities that are in PKCS#12 format.\n"); ++ else if(!strcasecompare(SSL_SET_OPTION(cert_type), "P12")) { ++ failf(data, "SSL: The Security framework only supports " ++ "loading identities that are in PKCS#12 format."); ++ return CURLE_SSL_CERTPROBLEM; ++ } + + err = CopyIdentityFromPKCS12File(ssl_cert, + SSL_SET_OPTION(key_passwd), &cert_and_key); + } +- else +- err = CopyIdentityWithLabel(ssl_cert, &cert_and_key); + + if(err == noErr && cert_and_key) { + SecCertificateRef cert = NULL; diff --git a/debian/patches/0024-44-CVE-2025-9086-curl-Cookie.patch b/debian/patches/0024-44-CVE-2025-9086-curl-Cookie.patch new file mode 100644 index 0000000000000000000000000000000000000000..491f89a1f454bee2bac58db4f204f8f93894ac65 --- /dev/null +++ b/debian/patches/0024-44-CVE-2025-9086-curl-Cookie.patch @@ -0,0 +1,83 @@ +From: Dwin +Date: Sat, 7 Nov 2026 07:56:36 +0000 +Subject: =?utf-8?b?ITQ0IENWRS0yMDI1LTkwODYg5a6J5YWo5pu05pawOiDkv67lpI1jdXJs?= + =?utf-8?b?IENvb2tpZei3r+W+hOi2iueVjOivu+WPlua8j+a0ng==?= + +Merge pull request !44 from Dwin/openkylin/yangtze +--- + lib/cookie.c | 38 +++++++++++++++----------------------- + 1 file changed, 15 insertions(+), 23 deletions(-) + +diff --git a/lib/cookie.c b/lib/cookie.c +index 27156ee..ff3e200 100644 +--- a/lib/cookie.c ++++ b/lib/cookie.c +@@ -299,36 +299,27 @@ static size_t cookiehash(const char * const domain) + */ + static char *sanitize_cookie_path(const char *cookie_path) + { +- size_t len; +- char *new_path = strdup(cookie_path); +- if(!new_path) +- return NULL; ++ size_t len = strlen(cookie_path); + +- /* some stupid site sends path attribute with '"'. */ +- len = strlen(new_path); +- if(new_path[0] == '\"') { +- memmove((void *)new_path, (const void *)(new_path + 1), len); ++ /* some sites send path attribute within '"'. */ ++ if(cookie_path[0] == '\"') { ++ cookie_path++; + len--; + } +- if(len && (new_path[len - 1] == '\"')) { +- new_path[len - 1] = 0x0; ++ if(len && (cookie_path[len - 1] == '\"')) + len--; +- } + + /* RFC6265 5.2.4 The Path Attribute */ +- if(new_path[0] != '/') { ++ if(cookie_path[0] != '/') + /* Let cookie-path be the default-path. */ +- free(new_path); +- new_path = strdup("/"); +- return new_path; +- } ++ return strdup("/"); + ++ /* remove trailing slash when path is non-empty */ + /* convert /hoge/ to /hoge */ +- if(len && new_path[len - 1] == '/') { +- new_path[len - 1] = 0x0; +- } ++ if(len > 1 && cookie_path[len - 1] == '/') ++ len--; + +- return new_path; ++ return Curl_memdup0(cookie_path, len); + } + + /* +@@ -1020,7 +1011,7 @@ Curl_cookie_add(struct Curl_easy *data, + if(clist->spath && co->spath) { + if(clist->secure && !co->secure && !secure) { + size_t cllen; +- const char *sep; ++ const char *sep = NULL; + + /* + * A non-secure cookie may not overlay an existing secure cookie. +@@ -1028,8 +1019,9 @@ Curl_cookie_add(struct Curl_easy *data, + * cookie "a" with for example path "/login/en", while the path + * "/loginhelper" is ok. + */ +- +- sep = strchr(clist->spath + 1, '/'); ++ DEBUGASSERT(clist->spath[0]); ++ if(clist->spath[0]) ++ sep = strchr(clist->spath + 1, '/'); + + if(sep) + cllen = sep - clist->spath; diff --git a/debian/patches/0025-54-fix-CVE-2021-22922-Wrong-content-via-Metalink-not.patch b/debian/patches/0025-54-fix-CVE-2021-22922-Wrong-content-via-Metalink-not.patch new file mode 100644 index 0000000000000000000000000000000000000000..6cc05a01260e5219d8c7ab2f3b5f90a9dd88cb24 --- /dev/null +++ b/debian/patches/0025-54-fix-CVE-2021-22922-Wrong-content-via-Metalink-not.patch @@ -0,0 +1,3916 @@ +From: gfc +Date: Sat, 7 Nov 2026 07:57:40 +0000 +Subject: !54 fix: CVE-2021-22922 - Wrong content via Metalink not discarded + +Merge pull request !54 from chenhongyi/openkylin/yangtze +--- + configure.ac | 91 +--- + docs/FEATURES | 7 +- + docs/cmdline-opts/metalink.d | 25 +- + docs/cmdline-opts/page-header | 5 +- + docs/cmdline-opts/version.d | 4 - + docs/examples/Makefile.m32 | 19 - + packages/vms/gnv_link_curl.com | 2 +- + src/Makefile.am | 11 +- + src/Makefile.inc | 2 - + src/Makefile.m32 | 19 - + src/Makefile.netware | 28 -- + src/tool_cfgable.h | 4 - + src/tool_getparam.c | 26 +- + src/tool_help.c | 3 - + src/tool_main.c | 1 - + src/tool_metalink.c | 1007 ---------------------------------------- + src/tool_metalink.h | 171 ------- + src/tool_operate.c | 171 +------ + src/tool_operate.h | 4 - + src/tool_operhlp.c | 1 - + src/tool_sdecls.h | 6 - + tests/data/Makefile.inc | 6 +- + tests/data/test2005 | 93 ---- + tests/data/test2006 | 116 ----- + tests/data/test2007 | 117 ----- + tests/data/test2008 | 109 ----- + tests/data/test2009 | 110 ----- + tests/data/test2010 | 109 ----- + tests/data/test2011 | 93 ---- + tests/data/test2012 | 92 ---- + tests/data/test2013 | 78 ---- + tests/data/test2014 | 78 ---- + tests/data/test2015 | 78 ---- + tests/data/test2016 | 78 ---- + tests/data/test2017 | 78 ---- + tests/data/test2018 | 78 ---- + tests/data/test2019 | 78 ---- + tests/data/test2020 | 78 ---- + tests/data/test2021 | 78 ---- + tests/data/test2022 | 78 ---- + tests/libtest/test1013.pl | 2 +- + tests/runtests.pl | 6 - + tests/unit/Makefile.inc | 8 +- + 43 files changed, 45 insertions(+), 3203 deletions(-) + delete mode 100644 src/tool_metalink.c + delete mode 100644 src/tool_metalink.h + delete mode 100644 tests/data/test2005 + delete mode 100644 tests/data/test2006 + delete mode 100644 tests/data/test2007 + delete mode 100644 tests/data/test2008 + delete mode 100644 tests/data/test2009 + delete mode 100644 tests/data/test2010 + delete mode 100644 tests/data/test2011 + delete mode 100644 tests/data/test2012 + delete mode 100644 tests/data/test2013 + delete mode 100644 tests/data/test2014 + delete mode 100644 tests/data/test2015 + delete mode 100644 tests/data/test2016 + delete mode 100644 tests/data/test2017 + delete mode 100644 tests/data/test2018 + delete mode 100644 tests/data/test2019 + delete mode 100644 tests/data/test2020 + delete mode 100644 tests/data/test2021 + delete mode 100644 tests/data/test2022 + +diff --git a/configure.ac b/configure.ac +index dd149b7..9592ed7 100755 +--- a/configure.ac ++++ b/configure.ac +@@ -174,7 +174,6 @@ curl_verbose_msg="enabled (--disable-verbose)" + curl_ldaps_msg="no (--enable-ldaps)" + curl_rtsp_msg="no (--enable-rtsp)" + curl_rtmp_msg="no (--with-librtmp)" +- curl_mtlnk_msg="no (--with-libmetalink)" + curl_psl_msg="no (--with-libpsl)" + + ssl_backends= +@@ -2700,93 +2699,8 @@ if test $with_libpsl != "no"; then + fi + AM_CONDITIONAL([USE_LIBPSL], [test "$curl_psl_msg" = "enabled"]) + +-dnl ********************************************************************** +-dnl Check for libmetalink +-dnl ********************************************************************** +- +-OPT_LIBMETALINK=no +- +-AC_ARG_WITH(libmetalink,dnl +-AC_HELP_STRING([--with-libmetalink=PATH],[where to look for libmetalink, PATH points to the installation root]) +-AC_HELP_STRING([--without-libmetalink], [disable libmetalink detection]), +- OPT_LIBMETALINK=$withval) +- +-if test X"$OPT_LIBMETALINK" != Xno; then +- +- addld="" +- addlib="" +- addcflags="" +- version="" +- libmetalinklib="" +- +- PKGTEST="no" +- if test "x$OPT_LIBMETALINK" = "xyes"; then +- dnl this is with no partiular path given +- PKGTEST="yes" +- CURL_CHECK_PKGCONFIG(libmetalink) +- else +- dnl When particular path is given, set PKG_CONFIG_LIBDIR using the path. +- LIBMETALINK_PCDIR="$OPT_LIBMETALINK/lib/pkgconfig" +- AC_MSG_NOTICE([PKG_CONFIG_LIBDIR will be set to "$LIBMETALINK_PCDIR"]) +- if test -f "$LIBMETALINK_PCDIR/libmetalink.pc"; then +- PKGTEST="yes" +- fi +- if test "$PKGTEST" = "yes"; then +- CURL_CHECK_PKGCONFIG(libmetalink, [$LIBMETALINK_PCDIR]) +- fi +- fi +- if test "$PKGTEST" = "yes" && test "$PKGCONFIG" != "no"; then +- addlib=`CURL_EXPORT_PCDIR([$LIBMETALINK_PCDIR]) dnl +- $PKGCONFIG --libs-only-l libmetalink` +- addld=`CURL_EXPORT_PCDIR([$LIBMETALINK_PCDIR]) dnl +- $PKGCONFIG --libs-only-L libmetalink` +- addcflags=`CURL_EXPORT_PCDIR([$LIBMETALINK_PCDIR]) dnl +- $PKGCONFIG --cflags-only-I libmetalink` +- version=`CURL_EXPORT_PCDIR([$LIBMETALINK_PCDIR]) dnl +- $PKGCONFIG --modversion libmetalink` +- libmetalinklib=`echo $addld | $SED -e 's/-L//'` +- fi +- if test -n "$addlib"; then +- +- clean_CPPFLAGS="$CPPFLAGS" +- clean_LDFLAGS="$LDFLAGS" +- clean_LIBS="$LIBS" +- CPPFLAGS="$clean_CPPFLAGS $addcflags" +- LDFLAGS="$clean_LDFLAGS $addld" +- LIBS="$addlib $clean_LIBS" +- AC_MSG_CHECKING([if libmetalink is recent enough]) +- AC_LINK_IFELSE([ +- AC_LANG_PROGRAM([[ +-# include +- ]],[[ +- if(0 != metalink_strerror(0)) /* added in 0.1.0 */ +- return 1; +- ]]) +- ],[ +- AC_MSG_RESULT([yes ($version)]) +- want_metalink="yes" +- ],[ +- AC_MSG_RESULT([no ($version)]) +- AC_MSG_NOTICE([libmetalink library defective or too old]) +- want_metalink="no" +- ]) +- CPPFLAGS="$clean_CPPFLAGS" +- LDFLAGS="$clean_LDFLAGS" +- LIBS="$clean_LIBS" +- if test "$want_metalink" = "yes"; then +- dnl finally libmetalink will be used +- AC_DEFINE(USE_METALINK, 1, [Define to enable metalink support]) +- LIBMETALINK_LIBS=$addlib +- LIBMETALINK_LDFLAGS=$addld +- LIBMETALINK_CPPFLAGS=$addcflags +- AC_SUBST([LIBMETALINK_LIBS]) +- AC_SUBST([LIBMETALINK_LDFLAGS]) +- AC_SUBST([LIBMETALINK_CPPFLAGS]) +- curl_mtlnk_msg="enabled" +- fi +- +- fi +-fi ++AC_ARG_WITH(libmetalink,, ++ AC_MSG_ERROR([--with-libmetalink no longer works!])) + + dnl ********************************************************************** + dnl Check for the presence of LIBSSH2 libraries and headers +@@ -4864,7 +4778,6 @@ AC_MSG_NOTICE([Configured to build curl/libcurl: + LDAPS: ${curl_ldaps_msg} + RTSP: ${curl_rtsp_msg} + RTMP: ${curl_rtmp_msg} +- Metalink: ${curl_mtlnk_msg} + PSL: ${curl_psl_msg} + Alt-svc: ${curl_altsvc_msg} + HTTP2: ${curl_h2_msg} +diff --git a/docs/FEATURES b/docs/FEATURES +index 68d38fc..1e488cb 100644 +--- a/docs/FEATURES ++++ b/docs/FEATURES +@@ -13,7 +13,6 @@ curl tool + - multiple file upload on a single command line + - custom maximum transfer rate + - redirectable stderr +- - metalink support (*13) + + libcurl + - full URL syntax with no length limit +@@ -77,7 +76,7 @@ HTTPS (*1) + FTP + - download + - authentication +- - Kerberos 5 (*14) ++ - Kerberos 5 (*13) + - active/passive using PORT, EPRT, PASV or EPSV + - single file size information (compare to HTTP HEAD) + - 'type=' URL support +@@ -199,6 +198,4 @@ FOOTNOTES + *10 = requires an SSL library that supports SSLv3 + *11 = requires libidn or Windows + *12 = requires libz +- *13 = requires libmetalink, and either an Apple or Microsoft operating +- system, or OpenSSL, or GnuTLS, or NSS +- *14 = requires a GSS-API implementation (such as Heimdal or MIT Kerberos) ++ *13 = requires a GSS-API implementation (such as Heimdal or MIT Kerberos) +diff --git a/docs/cmdline-opts/metalink.d b/docs/cmdline-opts/metalink.d +index 81fc8bc..8ce377f 100644 +--- a/docs/cmdline-opts/metalink.d ++++ b/docs/cmdline-opts/metalink.d +@@ -1,26 +1,7 @@ + Long: metalink + Help: Process given URLs as metalink XML file + Added: 7.27.0 +-Requires: metalink + --- +-This option can tell curl to parse and process a given URI as Metalink file +-(both version 3 and 4 (RFC 5854) are supported) and make use of the mirrors +-listed within for failover if there are errors (such as the file or server not +-being available). It will also verify the hash of the file after the download +-completes. The Metalink file itself is downloaded and processed in memory and +-not stored in the local file system. +- +-Example to use a remote Metalink file: +- +- curl --metalink http://www.example.com/example.metalink +- +-To use a Metalink file in the local file system, use FILE protocol (file://): +- +- curl --metalink file://example.metalink +- +-Please note that if FILE protocol is disabled, there is no way to use a local +-Metalink file at the time of this writing. Also note that if --metalink and +---include are used together, --include will be ignored. This is because +-including headers in the response will break Metalink parser and if the +-headers are included in the file described in Metalink file, hash check will +-fail. ++This option was previously used to specify a metalink resource. Metalink ++support has unfortunately been disabled in curl since 7.78.0 due to security ++reasons. +diff --git a/docs/cmdline-opts/page-header b/docs/cmdline-opts/page-header +index 51f45ed..82e7f9b 100644 +--- a/docs/cmdline-opts/page-header ++++ b/docs/cmdline-opts/page-header +@@ -36,9 +36,8 @@ and TFTP). The command is designed to work without user interaction. + + curl offers a busload of useful tricks like proxy support, user + authentication, FTP upload, HTTP post, SSL connections, cookies, file transfer +-resume, Metalink, and more. As you will see below, the number of features will +-make your head spin! +- ++resume and more. As you will see below, the number of features will make your ++head spin! + curl is powered by libcurl for all transfer-related features. See + \fIlibcurl(3)\fP for details. + .SH URL +diff --git a/docs/cmdline-opts/version.d b/docs/cmdline-opts/version.d +index cd35f27..5f30f52 100644 +--- a/docs/cmdline-opts/version.d ++++ b/docs/cmdline-opts/version.d +@@ -48,10 +48,6 @@ HTTP/2 support has been built-in. + Unix sockets support is provided. + .IP "HTTPS-proxy" + This curl is built to support HTTPS proxy. +-.IP "Metalink" +-This curl supports Metalink (both version 3 and 4 (RFC 5854)), which +-describes mirrors and hashes. curl will use mirrors for failover if +-there are errors (such as the file or server not being available). + .IP "PSL" + PSL is short for Public Suffix List and means that this curl has been built + with knowledge about "public suffixes". +diff --git a/docs/examples/Makefile.m32 b/docs/examples/Makefile.m32 +index 160afb6..49703a1 100644 +--- a/docs/examples/Makefile.m32 ++++ b/docs/examples/Makefile.m32 +@@ -55,10 +55,6 @@ endif + ifndef LIBRTMP_PATH + LIBRTMP_PATH = ../../../librtmp-2.4 + endif +-# Edit the path below to point to the base of your libmetalink package. +-ifndef LIBMETALINK_PATH +-LIBMETALINK_PATH = ../../../libmetalink-0.1.3 +-endif + # Edit the path below to point to the base of your libexpat package. + ifndef LIBEXPAT_PATH + LIBEXPAT_PATH = ../../../expat-2.1.0 +@@ -198,9 +194,6 @@ endif + ifeq ($(findstring -ipv6,$(CFG)),-ipv6) + IPV6 = 1 + endif +-ifeq ($(findstring -metalink,$(CFG)),-metalink) +-METALINK = 1 +-endif + ifeq ($(findstring -winssl,$(CFG)),-winssl) + WINSSL = 1 + SSPI = 1 +@@ -303,18 +296,6 @@ ifdef WINIDN + curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz + endif + endif +-ifdef METALINK +- INCLUDES += -I"$(LIBMETALINK_PATH)/include" +- CFLAGS += -DUSE_METALINK +- curl_LDADD += -L"$(LIBMETALINK_PATH)/lib" -lmetalink +- ifndef DYN +- ifeq ($(findstring libexpat_metalink_parser.o,$(shell $(AR) t "$(LIBMETALINK_PATH)/lib/libmetalink.a")),libexpat_metalink_parser.o) +- curl_LDADD += -L"$(LIBEXPAT_PATH)/lib" -lexpat +- else +- curl_LDADD += -L"$(LIBXML2_PATH)/lib" -lxml2 +- endif +- endif +-endif + ifdef SSPI + CFLAGS += -DUSE_WINDOWS_SSPI + endif +diff --git a/packages/vms/gnv_link_curl.com b/packages/vms/gnv_link_curl.com +index 7ec4ecb..2fc69b0 100644 +--- a/packages/vms/gnv_link_curl.com ++++ b/packages/vms/gnv_link_curl.com +@@ -408,7 +408,7 @@ $ link'ldebug'/exe=[.src]curl.exe/dsf=[.src]curl.dsf - + [.src]curl-tool_getpass.o, [.src]curl-tool_help.o, - + [.src]curl-tool_helpers.o, [.src]curl-tool_homedir.o, - + [.src]curl-tool_hugehelp.o, [.src]curl-tool_libinfo.o, - +- [.src]curl-tool_metalink.o, [.src]curl-tool_mfiles.o, - ++ [.src]curl-tool_mfiles.o, - + [.src]curl-tool_msgs.o, [.src]curl-tool_operate.o, - + [.src]curl-tool_operhlp.o, [.src]curl-tool_panykey.o, - + [.src]curl-tool_paramhlp.o, [.src]curl-tool_parsecfg.o, - +diff --git a/src/Makefile.am b/src/Makefile.am +index fe14b72..05bd5c2 100644 +--- a/src/Makefile.am ++++ b/src/Makefile.am +@@ -5,7 +5,7 @@ + # | (__| |_| | _ <| |___ + # \___|\___/|_| \_\_____| + # +-# Copyright (C) 1998 - 2019, Daniel Stenberg, , et al. ++# Copyright (C) 1998 - 2021, Daniel Stenberg, , et al. + # + # This software is licensed as described in the file COPYING, which + # you should have received as part of this distribution. The terms +@@ -61,18 +61,15 @@ CFLAGS += @CURL_CFLAG_EXTRAS@ + LIBS = $(BLANK_AT_MAKETIME) + + if USE_EXPLICIT_LIB_DEPS +-curl_LDADD = $(top_builddir)/lib/libcurl-nss.la @LIBMETALINK_LIBS@ @LIBCURL_LIBS@ ++curl_LDADD = $(top_builddir)/lib/libcurl-nss.la @LIBCURL_LIBS@ + else +-curl_LDADD = $(top_builddir)/lib/libcurl-nss.la @LIBMETALINK_LIBS@ @NSS_LIBS@ @SSL_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@ ++curl_LDADD = $(top_builddir)/lib/libcurl-nss.la @NSS_LIBS@ @SSL_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@ + endif + +-curl_LDFLAGS = @LIBMETALINK_LDFLAGS@ +-curl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBMETALINK_CPPFLAGS) +- + # if unit tests are enabled, build a static library to link them with + if BUILD_UNITTESTS + noinst_LTLIBRARIES = libcurltool.la +-libcurltool_la_CPPFLAGS = $(LIBMETALINK_CPPFLAGS) $(AM_CPPFLAGS) \ ++libcurltool_la_CPPFLAGS = $(AM_CPPFLAGS) \ + -DCURL_STATICLIB -DUNITTESTS + libcurltool_la_CFLAGS = + libcurltool_la_LDFLAGS = -static $(LINKFLAGS) +diff --git a/src/Makefile.inc b/src/Makefile.inc +index dd6b9d3..1e4ccdf 100644 +--- a/src/Makefile.inc ++++ b/src/Makefile.inc +@@ -47,7 +47,6 @@ CURL_CFILES = \ + tool_hugehelp.c \ + tool_libinfo.c \ + tool_main.c \ +- tool_metalink.c \ + tool_msgs.c \ + tool_operate.c \ + tool_operhlp.c \ +@@ -89,7 +88,6 @@ CURL_HFILES = \ + tool_hugehelp.h \ + tool_libinfo.h \ + tool_main.h \ +- tool_metalink.h \ + tool_msgs.h \ + tool_operate.h \ + tool_operhlp.h \ +diff --git a/src/Makefile.m32 b/src/Makefile.m32 +index e13db04..aaebeb2 100644 +--- a/src/Makefile.m32 ++++ b/src/Makefile.m32 +@@ -55,10 +55,6 @@ endif + ifndef LIBRTMP_PATH + LIBRTMP_PATH = ../../librtmp-2.4 + endif +-# Edit the path below to point to the base of your libmetalink package. +-ifndef LIBMETALINK_PATH +-LIBMETALINK_PATH = ../../libmetalink-0.1.3 +-endif + # Edit the path below to point to the base of your libexpat package. + ifndef LIBEXPAT_PATH + LIBEXPAT_PATH = ../../expat-2.1.0 +@@ -207,9 +203,6 @@ endif + ifeq ($(findstring -ipv6,$(CFG)),-ipv6) + IPV6 = 1 + endif +-ifeq ($(findstring -metalink,$(CFG)),-metalink) +-METALINK = 1 +-endif + ifeq ($(findstring -winssl,$(CFG)),-winssl) + WINSSL = 1 + SSPI = 1 +@@ -321,18 +314,6 @@ ifdef WINIDN + curl_LDADD += -L"$(WINIDN_PATH)" -lnormaliz + endif + endif +-ifdef METALINK +- INCLUDES += -I"$(LIBMETALINK_PATH)/include" +- CFLAGS += -DUSE_METALINK +- curl_LDADD += -L"$(LIBMETALINK_PATH)/lib" -lmetalink +- ifndef DYN +- ifeq ($(findstring libexpat_metalink_parser.o,$(shell $(AR) t "$(LIBMETALINK_PATH)/lib/libmetalink.a")),libexpat_metalink_parser.o) +- curl_LDADD += -L"$(LIBEXPAT_PATH)/lib" -lexpat +- else +- curl_LDADD += -L"$(LIBXML2_PATH)/lib" -lxml2 +- endif +- endif +-endif + ifdef SSPI + CFLAGS += -DUSE_WINDOWS_SSPI + endif +diff --git a/src/Makefile.netware b/src/Makefile.netware +index 20d9807..1b1345d 100644 +--- a/src/Makefile.netware ++++ b/src/Makefile.netware +@@ -69,11 +69,6 @@ ifndef FBOPENSSL_PATH + FBOPENSSL_PATH = ../../fbopenssl-0.4 + endif + +-# Edit the path below to point to the base of your libmetalink package. +-ifndef LIBMETALINK_PATH +-LIBMETALINK_PATH = ../../libmetalink-0.1.2 +-endif +- + # Edit the path below to point to the base of your libexpat package. + ifndef LIBEXPAT_PATH + LIBEXPAT_PATH = ../../expat-2.1.0 +@@ -243,10 +238,6 @@ endif + ifeq ($(findstring -idn,$(CFG)),-idn) + WITH_IDN = 1 + endif +-ifeq ($(findstring -metalink,$(CFG)),-metalink) +-WITH_METALINK = 1 +-WITH_SSL = 1 +-endif + ifeq ($(findstring -nghttp2,$(CFG)),-nghttp2) + WITH_NGHTTP2 = 1 + endif +@@ -301,25 +292,6 @@ ifdef WITH_NGHTTP2 + INCLUDES += -I$(NGHTTP2_PATH)/include + LDLIBS += $(NGHTTP2_PATH)/lib/libnghttp2.$(LIBEXT) + endif +-ifdef WITH_METALINK +- CFLAGS += -DUSE_METALINK +- INCLUDES += -I$(OPENSSL_PATH)/outinc_nw_$(LIBARCH_L) +- INCLUDES += -I$(LIBMETALINK_PATH)/include +- LDLIBS += $(LIBMETALINK_PATH)/lib/libmetalink.$(LIBEXT) +- ifdef WITH_LIBEXPAT +- ifeq ($(LIBARCH),LIBC) +- IMPORTS += @$(LIBEXPAT_PATH)/imports/expatlbc.imp +- MODULES += expatlbc +- else +- IMPORTS += @$(LIBEXPAT_PATH)/imports/expatlib.imp +- MODULES += expatlib +- endif +-else +-ifdef WITH_LIBXML2 +- IMPORTS += @$(LIBXML2_PATH)/lib/libxml2.imp +- MODULES += libxml2 +-endif +-endif + endif + + ifeq ($(LIBARCH),LIBC) +diff --git a/src/tool_cfgable.h b/src/tool_cfgable.h +index 32e811e..27d90ba 100644 +--- a/src/tool_cfgable.h ++++ b/src/tool_cfgable.h +@@ -23,7 +23,6 @@ + ***************************************************************************/ + #include "tool_setup.h" + #include "tool_sdecls.h" +-#include "tool_metalink.h" + #include "tool_urlglob.h" + #include "tool_formparse.h" + +@@ -253,9 +252,6 @@ struct OperationConfig { + bool ssl_no_revoke; /* disable SSL certificate revocation checks */ + /*bool proxy_ssl_no_revoke; */ + +- bool use_metalink; /* process given URLs as metalink XML file */ +- metalinkfile *metalinkfile_list; /* point to the first node */ +- metalinkfile *metalinkfile_last; /* point to the last/current node */ + char *oauth_bearer; /* OAuth 2.0 bearer token */ + bool nonpn; /* enable/disable TLS NPN extension */ + bool noalpn; /* enable/disable TLS ALPN extension */ +diff --git a/src/tool_getparam.c b/src/tool_getparam.c +index 8191ed5..07e6e08 100644 +--- a/src/tool_getparam.c ++++ b/src/tool_getparam.c +@@ -36,7 +36,6 @@ + #include "tool_getparam.h" + #include "tool_helpers.h" + #include "tool_libinfo.h" +-#include "tool_metalink.h" + #include "tool_msgs.h" + #include "tool_paramhlp.h" + #include "tool_parsecfg.h" +@@ -1085,29 +1084,8 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */ + GetStr(&config->mail_auth, nextarg); + break; + case 'J': /* --metalink */ +- { +-#ifdef USE_METALINK +- int mlmaj, mlmin, mlpatch; +- metalink_get_version(&mlmaj, &mlmin, &mlpatch); +- if((mlmaj*10000)+(mlmin*100) + mlpatch < CURL_REQ_LIBMETALINK_VERS) { +- warnf(global, +- "--metalink option cannot be used because the version of " +- "the linked libmetalink library is too old. " +- "Required: %d.%d.%d, found %d.%d.%d\n", +- CURL_REQ_LIBMETALINK_MAJOR, +- CURL_REQ_LIBMETALINK_MINOR, +- CURL_REQ_LIBMETALINK_PATCH, +- mlmaj, mlmin, mlpatch); +- return PARAM_BAD_USE; +- } +- else +- config->use_metalink = toggle; +-#else +- warnf(global, "--metalink option is ignored because the binary is " +- "built without the Metalink support.\n"); +-#endif +- break; +- } ++ errorf(global, "--metalink is disabled\n"); ++ return PARAM_BAD_USE; + case '6': /* --sasl-authzid */ + GetStr(&config->sasl_authzid, nextarg); + break; +diff --git a/src/tool_help.c b/src/tool_help.c +index 8d3f345..e7e45c6 100644 +--- a/src/tool_help.c ++++ b/src/tool_help.c +@@ -606,9 +606,6 @@ void tool_version_info(void) + if(curlinfo->features & feats[i].bitmask) + featp[numfeat++] = (char *)feats[i].name; + } +-#ifdef USE_METALINK +- featp[numfeat++] = (char *)"Metalink"; +-#endif + qsort(&featp[0], numfeat, sizeof(char *), featcomp); + for(i = 0; i< numfeat; i++) + printf(" %s", featp[i]); +diff --git a/src/tool_main.c b/src/tool_main.c +index 06923c3..4386ee9 100644 +--- a/src/tool_main.c ++++ b/src/tool_main.c +@@ -208,7 +208,6 @@ static void main_free(struct GlobalConfig *config) + /* Main cleanup */ + curl_global_cleanup(); + convert_cleanup(); +- metalink_cleanup(); + #ifdef USE_NSS + if(PR_Initialized()) { + /* prevent valgrind from reporting still reachable mem from NSRP arenas */ +diff --git a/src/tool_metalink.c b/src/tool_metalink.c +deleted file mode 100644 +index 6d62f2d..0000000 +--- a/src/tool_metalink.c ++++ /dev/null +@@ -1,1007 +0,0 @@ +-/*************************************************************************** +- * _ _ ____ _ +- * Project ___| | | | _ \| | +- * / __| | | | |_) | | +- * | (__| |_| | _ <| |___ +- * \___|\___/|_| \_\_____| +- * +- * Copyright (C) 1998 - 2019, Daniel Stenberg, , et al. +- * +- * This software is licensed as described in the file COPYING, which +- * you should have received as part of this distribution. The terms +- * are also available at https://curl.haxx.se/docs/copyright.html. +- * +- * You may opt to use, copy, modify, merge, publish, distribute and/or sell +- * copies of the Software, and permit persons to whom the Software is +- * furnished to do so, under the terms of the COPYING file. +- * +- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +- * KIND, either express or implied. +- * +- ***************************************************************************/ +-#include "tool_setup.h" +- +-#ifdef USE_METALINK +- +-#include +-#include +- +-#ifdef HAVE_FCNTL_H +-# include +-#endif +- +-#undef HAVE_NSS_CONTEXT +- +-#ifdef USE_OPENSSL +-# include +-# include +-#elif defined(USE_GNUTLS_NETTLE) +-# include +-# include +-# define MD5_CTX struct md5_ctx +-# define SHA_CTX struct sha1_ctx +-# define SHA256_CTX struct sha256_ctx +-#elif defined(USE_GNUTLS) +-# include +-# define MD5_CTX gcry_md_hd_t +-# define SHA_CTX gcry_md_hd_t +-# define SHA256_CTX gcry_md_hd_t +-#elif defined(USE_NSS) +-# include +-# include +-# define MD5_CTX void * +-# define SHA_CTX void * +-# define SHA256_CTX void * +-# define HAVE_NSS_CONTEXT +- static NSSInitContext *nss_context; +-#elif defined(USE_POLARSSL) +-# include +-# include +-# include +-# define MD5_CTX md5_context +-# define SHA_CTX sha1_context +-# define SHA256_CTX sha256_context +-#elif (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \ +- (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1040)) || \ +- (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \ +- (__IPHONE_OS_VERSION_MAX_ALLOWED >= 20000)) +-/* For Apple operating systems: CommonCrypto has the functions we need. +- The library's headers are even backward-compatible with OpenSSL's +- headers as long as we define COMMON_DIGEST_FOR_OPENSSL first. +- +- These functions are available on Tiger and later, as well as iOS 2.0 +- and later. If you're building for an older cat, well, sorry. */ +-# define COMMON_DIGEST_FOR_OPENSSL +-# include +-#elif defined(WIN32) +-/* For Windows: If no other crypto library is provided, we fallback +- to the hash functions provided within the Microsoft Windows CryptoAPI */ +-# include +-/* Custom structure in order to store the required provider and hash handle */ +-struct win32_crypto_hash { +- HCRYPTPROV hCryptProv; +- HCRYPTHASH hHash; +-}; +-/* Custom Microsoft AES Cryptographic Provider defines required for MinGW */ +-# ifndef ALG_SID_SHA_256 +-# define ALG_SID_SHA_256 12 +-# endif +-# ifndef CALG_SHA_256 +-# define CALG_SHA_256 (ALG_CLASS_HASH | ALG_TYPE_ANY | ALG_SID_SHA_256) +-# endif +-# define MD5_CTX struct win32_crypto_hash +-# define SHA_CTX struct win32_crypto_hash +-# define SHA256_CTX struct win32_crypto_hash +-#else +-# error "Can't compile METALINK support without a crypto library." +-#endif +- +-#define ENABLE_CURLX_PRINTF +-/* use our own printf() functions */ +-#include "curlx.h" +- +-#include "tool_getparam.h" +-#include "tool_paramhlp.h" +-#include "tool_cfgable.h" +-#include "tool_metalink.h" +-#include "tool_operate.h" +-#include "tool_msgs.h" +- +-#include "memdebug.h" /* keep this as LAST include */ +- +-/* Copied from tool_getparam.c */ +-#define GetStr(str,val) do { \ +- if(*(str)) { \ +- free(*(str)); \ +- *(str) = NULL; \ +- } \ +- if((val)) \ +- *(str) = strdup((val)); \ +- if(!(val)) \ +- return PARAM_NO_MEM; \ +-} while(0) +- +-#if defined(USE_OPENSSL) +-/* Functions are already defined */ +-#elif defined(USE_GNUTLS_NETTLE) +- +-static int MD5_Init(MD5_CTX *ctx) +-{ +- md5_init(ctx); +- return 1; +-} +- +-static void MD5_Update(MD5_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- md5_update(ctx, inputLen, input); +-} +- +-static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx) +-{ +- md5_digest(ctx, 16, digest); +-} +- +-static int SHA1_Init(SHA_CTX *ctx) +-{ +- sha1_init(ctx); +- return 1; +-} +- +-static void SHA1_Update(SHA_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- sha1_update(ctx, inputLen, input); +-} +- +-static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx) +-{ +- sha1_digest(ctx, 20, digest); +-} +- +-static int SHA256_Init(SHA256_CTX *ctx) +-{ +- sha256_init(ctx); +- return 1; +-} +- +-static void SHA256_Update(SHA256_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- sha256_update(ctx, inputLen, input); +-} +- +-static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx) +-{ +- sha256_digest(ctx, 32, digest); +-} +- +-#elif defined(USE_GNUTLS) +- +-static int MD5_Init(MD5_CTX *ctx) +-{ +- gcry_md_open(ctx, GCRY_MD_MD5, 0); +- return 1; +-} +- +-static void MD5_Update(MD5_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- gcry_md_write(*ctx, input, inputLen); +-} +- +-static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx) +-{ +- memcpy(digest, gcry_md_read(*ctx, 0), 16); +- gcry_md_close(*ctx); +-} +- +-static int SHA1_Init(SHA_CTX *ctx) +-{ +- gcry_md_open(ctx, GCRY_MD_SHA1, 0); +- return 1; +-} +- +-static void SHA1_Update(SHA_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- gcry_md_write(*ctx, input, inputLen); +-} +- +-static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx) +-{ +- memcpy(digest, gcry_md_read(*ctx, 0), 20); +- gcry_md_close(*ctx); +-} +- +-static int SHA256_Init(SHA256_CTX *ctx) +-{ +- gcry_md_open(ctx, GCRY_MD_SHA256, 0); +- return 1; +-} +- +-static void SHA256_Update(SHA256_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- gcry_md_write(*ctx, input, inputLen); +-} +- +-static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx) +-{ +- memcpy(digest, gcry_md_read(*ctx, 0), 32); +- gcry_md_close(*ctx); +-} +- +-#elif defined(USE_NSS) +- +-static int nss_hash_init(void **pctx, SECOidTag hash_alg) +-{ +- PK11Context *ctx; +- +- /* we have to initialize NSS if not initialized already */ +- if(!NSS_IsInitialized() && !nss_context) { +- static NSSInitParameters params; +- params.length = sizeof(params); +- nss_context = NSS_InitContext("", "", "", "", ¶ms, NSS_INIT_READONLY +- | NSS_INIT_NOCERTDB | NSS_INIT_NOMODDB | NSS_INIT_FORCEOPEN +- | NSS_INIT_NOROOTINIT | NSS_INIT_OPTIMIZESPACE | NSS_INIT_PK11RELOAD); +- } +- +- ctx = PK11_CreateDigestContext(hash_alg); +- if(!ctx) +- return /* failure */ 0; +- +- if(PK11_DigestBegin(ctx) != SECSuccess) { +- PK11_DestroyContext(ctx, PR_TRUE); +- return /* failure */ 0; +- } +- +- *pctx = ctx; +- return /* success */ 1; +-} +- +-static void nss_hash_final(void **pctx, unsigned char *out, unsigned int len) +-{ +- PK11Context *ctx = *pctx; +- unsigned int outlen; +- PK11_DigestFinal(ctx, out, &outlen, len); +- PK11_DestroyContext(ctx, PR_TRUE); +-} +- +-static int MD5_Init(MD5_CTX *pctx) +-{ +- return nss_hash_init(pctx, SEC_OID_MD5); +-} +- +-static void MD5_Update(MD5_CTX *pctx, +- const unsigned char *input, +- unsigned int input_len) +-{ +- PK11_DigestOp(*pctx, input, input_len); +-} +- +-static void MD5_Final(unsigned char digest[16], MD5_CTX *pctx) +-{ +- nss_hash_final(pctx, digest, 16); +-} +- +-static int SHA1_Init(SHA_CTX *pctx) +-{ +- return nss_hash_init(pctx, SEC_OID_SHA1); +-} +- +-static void SHA1_Update(SHA_CTX *pctx, +- const unsigned char *input, +- unsigned int input_len) +-{ +- PK11_DigestOp(*pctx, input, input_len); +-} +- +-static void SHA1_Final(unsigned char digest[20], SHA_CTX *pctx) +-{ +- nss_hash_final(pctx, digest, 20); +-} +- +-static int SHA256_Init(SHA256_CTX *pctx) +-{ +- return nss_hash_init(pctx, SEC_OID_SHA256); +-} +- +-static void SHA256_Update(SHA256_CTX *pctx, +- const unsigned char *input, +- unsigned int input_len) +-{ +- PK11_DigestOp(*pctx, input, input_len); +-} +- +-static void SHA256_Final(unsigned char digest[32], SHA256_CTX *pctx) +-{ +- nss_hash_final(pctx, digest, 32); +-} +- +-#elif defined(USE_POLARSSL) +- +-static int MD5_Init(MD5_CTX *ctx) +-{ +- md5_starts(ctx); +- return 1; +-} +- +-static void MD5_Update(MD5_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- md5_update(ctx, input, inputLen); +-} +- +-static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx) +-{ +- md5_finish(ctx, digest); +-} +- +-static int SHA1_Init(SHA_CTX *ctx) +-{ +- sha1_starts(ctx); +- return 1; +-} +- +-static void SHA1_Update(SHA_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- sha1_update(ctx, input, inputLen); +-} +- +-static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx) +-{ +- sha1_finish(ctx, digest); +-} +- +-static int SHA256_Init(SHA256_CTX *ctx) +-{ +- sha256_starts(ctx, 0); /* 0 = sha256 */ +- return 1; +-} +- +-static void SHA256_Update(SHA256_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- sha256_update(ctx, input, inputLen); +-} +- +-static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx) +-{ +- sha256_finish(ctx, digest); +-} +- +-#elif defined(WIN32) +- +-static void win32_crypto_final(struct win32_crypto_hash *ctx, +- unsigned char *digest, +- unsigned int digestLen) +-{ +- unsigned long length; +- CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0); +- if(length == digestLen) +- CryptGetHashParam(ctx->hHash, HP_HASHVAL, digest, &length, 0); +- if(ctx->hHash) +- CryptDestroyHash(ctx->hHash); +- if(ctx->hCryptProv) +- CryptReleaseContext(ctx->hCryptProv, 0); +-} +- +-static int MD5_Init(MD5_CTX *ctx) +-{ +- if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, +- PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { +- CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash); +- } +- return 1; +-} +- +-static void MD5_Update(MD5_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0); +-} +- +-static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx) +-{ +- win32_crypto_final(ctx, digest, 16); +-} +- +-static int SHA1_Init(SHA_CTX *ctx) +-{ +- if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, +- PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) { +- CryptCreateHash(ctx->hCryptProv, CALG_SHA1, 0, 0, &ctx->hHash); +- } +- return 1; +-} +- +-static void SHA1_Update(SHA_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0); +-} +- +-static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx) +-{ +- win32_crypto_final(ctx, digest, 20); +-} +- +-static int SHA256_Init(SHA256_CTX *ctx) +-{ +- if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, +- PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) { +- CryptCreateHash(ctx->hCryptProv, CALG_SHA_256, 0, 0, &ctx->hHash); +- } +- return 1; +-} +- +-static void SHA256_Update(SHA256_CTX *ctx, +- const unsigned char *input, +- unsigned int inputLen) +-{ +- CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0); +-} +- +-static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx) +-{ +- win32_crypto_final(ctx, digest, 32); +-} +- +-#endif /* CRYPTO LIBS */ +- +-const digest_params MD5_DIGEST_PARAMS[] = { +- { +- CURLX_FUNCTION_CAST(Curl_digest_init_func, MD5_Init), +- CURLX_FUNCTION_CAST(Curl_digest_update_func, MD5_Update), +- CURLX_FUNCTION_CAST(Curl_digest_final_func, MD5_Final), +- sizeof(MD5_CTX), +- 16 +- } +-}; +- +-const digest_params SHA1_DIGEST_PARAMS[] = { +- { +- CURLX_FUNCTION_CAST(Curl_digest_init_func, SHA1_Init), +- CURLX_FUNCTION_CAST(Curl_digest_update_func, SHA1_Update), +- CURLX_FUNCTION_CAST(Curl_digest_final_func, SHA1_Final), +- sizeof(SHA_CTX), +- 20 +- } +-}; +- +-const digest_params SHA256_DIGEST_PARAMS[] = { +- { +- CURLX_FUNCTION_CAST(Curl_digest_init_func, SHA256_Init), +- CURLX_FUNCTION_CAST(Curl_digest_update_func, SHA256_Update), +- CURLX_FUNCTION_CAST(Curl_digest_final_func, SHA256_Final), +- sizeof(SHA256_CTX), +- 32 +- } +-}; +- +-static const metalink_digest_def SHA256_DIGEST_DEF[] = { +- {"sha-256", SHA256_DIGEST_PARAMS} +-}; +- +-static const metalink_digest_def SHA1_DIGEST_DEF[] = { +- {"sha-1", SHA1_DIGEST_PARAMS} +-}; +- +-static const metalink_digest_def MD5_DIGEST_DEF[] = { +- {"md5", MD5_DIGEST_PARAMS} +-}; +- +-/* +- * The alias of supported hash functions in the order by preference +- * (basically stronger hash comes first). We included "sha-256" and +- * "sha256". The former is the name defined in the IANA registry named +- * "Hash Function Textual Names". The latter is widely (and +- * historically) used in Metalink version 3. +- */ +-static const metalink_digest_alias digest_aliases[] = { +- {"sha-256", SHA256_DIGEST_DEF}, +- {"sha256", SHA256_DIGEST_DEF}, +- {"sha-1", SHA1_DIGEST_DEF}, +- {"sha1", SHA1_DIGEST_DEF}, +- {"md5", MD5_DIGEST_DEF}, +- {NULL, NULL} +-}; +- +-digest_context *Curl_digest_init(const digest_params *dparams) +-{ +- digest_context *ctxt; +- +- /* Create digest context */ +- ctxt = malloc(sizeof(*ctxt)); +- +- if(!ctxt) +- return ctxt; +- +- ctxt->digest_hashctx = malloc(dparams->digest_ctxtsize); +- +- if(!ctxt->digest_hashctx) { +- free(ctxt); +- return NULL; +- } +- +- ctxt->digest_hash = dparams; +- +- if(dparams->digest_init(ctxt->digest_hashctx) != 1) { +- free(ctxt->digest_hashctx); +- free(ctxt); +- return NULL; +- } +- +- return ctxt; +-} +- +-int Curl_digest_update(digest_context *context, +- const unsigned char *data, +- unsigned int len) +-{ +- (*context->digest_hash->digest_update)(context->digest_hashctx, data, len); +- +- return 0; +-} +- +-int Curl_digest_final(digest_context *context, unsigned char *result) +-{ +- if(result) +- (*context->digest_hash->digest_final)(result, context->digest_hashctx); +- +- free(context->digest_hashctx); +- free(context); +- +- return 0; +-} +- +-static unsigned char hex_to_uint(const char *s) +-{ +- char buf[3]; +- unsigned long val; +- buf[0] = s[0]; +- buf[1] = s[1]; +- buf[2] = 0; +- val = strtoul(buf, NULL, 16); +- return (unsigned char)(val&0xff); +-} +- +-/* +- * Check checksum of file denoted by filename. The expected hash value +- * is given in hex_hash which is hex-encoded string. +- * +- * This function returns 1 if it succeeds or one of the following +- * integers: +- * +- * 0: +- * Checksum didn't match. +- * -1: +- * Could not open file; or could not read data from file. +- * -2: +- * Hash algorithm not available. +- */ +-static int check_hash(const char *filename, +- const metalink_digest_def *digest_def, +- const unsigned char *digest, FILE *error) +-{ +- unsigned char *result; +- digest_context *dctx; +- int check_ok, flags, fd; +- +- flags = O_RDONLY; +-#ifdef O_BINARY +- /* O_BINARY is required in order to avoid binary EOF in text mode */ +- flags |= O_BINARY; +-#endif +- +- fd = open(filename, flags); +- if(fd == -1) { +- fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename, +- digest_def->hash_name, strerror(errno)); +- return -1; +- } +- +- dctx = Curl_digest_init(digest_def->dparams); +- if(!dctx) { +- fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename, +- digest_def->hash_name, "failed to initialize hash algorithm"); +- close(fd); +- return -2; +- } +- +- result = malloc(digest_def->dparams->digest_resultlen); +- if(!result) { +- close(fd); +- Curl_digest_final(dctx, NULL); +- return -1; +- } +- while(1) { +- unsigned char buf[4096]; +- ssize_t len = read(fd, buf, sizeof(buf)); +- if(len == 0) { +- break; +- } +- else if(len == -1) { +- fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename, +- digest_def->hash_name, strerror(errno)); +- Curl_digest_final(dctx, result); +- close(fd); +- return -1; +- } +- Curl_digest_update(dctx, buf, (unsigned int)len); +- } +- Curl_digest_final(dctx, result); +- check_ok = memcmp(result, digest, +- digest_def->dparams->digest_resultlen) == 0; +- /* sha*sum style verdict output */ +- if(check_ok) +- fprintf(error, "Metalink: validating (%s) [%s] OK\n", filename, +- digest_def->hash_name); +- else +- fprintf(error, "Metalink: validating (%s) [%s] FAILED (digest mismatch)\n", +- filename, digest_def->hash_name); +- +- free(result); +- close(fd); +- return check_ok; +-} +- +-int metalink_check_hash(struct GlobalConfig *config, +- metalinkfile *mlfile, +- const char *filename) +-{ +- int rv; +- fprintf(config->errors, "Metalink: validating (%s)...\n", filename); +- if(mlfile->checksum == NULL) { +- fprintf(config->errors, +- "Metalink: validating (%s) FAILED (digest missing)\n", filename); +- return -2; +- } +- rv = check_hash(filename, mlfile->checksum->digest_def, +- mlfile->checksum->digest, config->errors); +- return rv; +-} +- +-static metalink_checksum * +-checksum_from_hex_digest(const metalink_digest_def *digest_def, +- const char *hex_digest) +-{ +- metalink_checksum *chksum; +- unsigned char *digest; +- size_t i; +- size_t len = strlen(hex_digest); +- digest = malloc(len/2); +- if(!digest) +- return 0; +- +- for(i = 0; i < len; i += 2) { +- digest[i/2] = hex_to_uint(hex_digest + i); +- } +- chksum = malloc(sizeof(metalink_checksum)); +- if(chksum) { +- chksum->digest_def = digest_def; +- chksum->digest = digest; +- } +- else +- free(digest); +- return chksum; +-} +- +-static metalink_resource *new_metalink_resource(const char *url) +-{ +- metalink_resource *res; +- res = malloc(sizeof(metalink_resource)); +- if(res) { +- res->next = NULL; +- res->url = strdup(url); +- if(!res->url) { +- free(res); +- return NULL; +- } +- } +- return res; +-} +- +-/* Returns nonzero if hex_digest is properly formatted; that is each +- letter is in [0-9A-Za-z] and the length of the string equals to the +- result length of digest * 2. */ +-static int check_hex_digest(const char *hex_digest, +- const metalink_digest_def *digest_def) +-{ +- size_t i; +- for(i = 0; hex_digest[i]; ++i) { +- char c = hex_digest[i]; +- if(!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || +- ('A' <= c && c <= 'Z'))) { +- return 0; +- } +- } +- return digest_def->dparams->digest_resultlen * 2 == i; +-} +- +-static metalinkfile *new_metalinkfile(metalink_file_t *fileinfo) +-{ +- metalinkfile *f; +- f = (metalinkfile*)malloc(sizeof(metalinkfile)); +- if(!f) +- return NULL; +- +- f->next = NULL; +- f->filename = strdup(fileinfo->name); +- if(!f->filename) { +- free(f); +- return NULL; +- } +- f->checksum = NULL; +- f->resource = NULL; +- if(fileinfo->checksums) { +- const metalink_digest_alias *digest_alias; +- for(digest_alias = digest_aliases; digest_alias->alias_name; +- ++digest_alias) { +- metalink_checksum_t **p; +- for(p = fileinfo->checksums; *p; ++p) { +- if(curl_strequal(digest_alias->alias_name, (*p)->type) && +- check_hex_digest((*p)->hash, digest_alias->digest_def)) { +- f->checksum = +- checksum_from_hex_digest(digest_alias->digest_def, +- (*p)->hash); +- break; +- } +- } +- if(f->checksum) { +- break; +- } +- } +- } +- if(fileinfo->resources) { +- metalink_resource_t **p; +- metalink_resource root, *tail; +- root.next = NULL; +- tail = &root; +- for(p = fileinfo->resources; *p; ++p) { +- metalink_resource *res; +- /* Filter by type if it is non-NULL. In Metalink v3, type +- includes the type of the resource. In curl, we are only +- interested in HTTP, HTTPS and FTP. In addition to them, +- Metalink v3 file may contain bittorrent type URL, which +- points to the BitTorrent metainfo file. We ignore it here. +- In Metalink v4, type was deprecated and all +- fileinfo->resources point to the target file. BitTorrent +- metainfo file URL may be appeared in fileinfo->metaurls. +- */ +- if((*p)->type == NULL || +- curl_strequal((*p)->type, "http") || +- curl_strequal((*p)->type, "https") || +- curl_strequal((*p)->type, "ftp") || +- curl_strequal((*p)->type, "ftps")) { +- res = new_metalink_resource((*p)->url); +- if(res) { +- tail->next = res; +- tail = res; +- } +- else { +- tail = root.next; +- +- /* clean up the linked list */ +- while(tail) { +- res = tail->next; +- free(tail->url); +- free(tail); +- tail = res; +- } +- free(f->filename); +- free(f); +- return NULL; +- } +- } +- } +- f->resource = root.next; +- } +- return f; +-} +- +-int parse_metalink(struct OperationConfig *config, struct OutStruct *outs, +- const char *metalink_url) +-{ +- metalink_error_t r; +- metalink_t* metalink; +- metalink_file_t **files; +- bool warnings = FALSE; +- +- /* metlaink_parse_final deletes outs->metalink_parser */ +- r = metalink_parse_final(outs->metalink_parser, NULL, 0, &metalink); +- outs->metalink_parser = NULL; +- if(r != 0) { +- return -1; +- } +- if(metalink->files == NULL) { +- fprintf(config->global->errors, "Metalink: parsing (%s) WARNING " +- "(missing or invalid file name)\n", +- metalink_url); +- metalink_delete(metalink); +- return -1; +- } +- for(files = metalink->files; *files; ++files) { +- struct getout *url; +- /* Skip an entry which has no resource. */ +- if(!(*files)->resources) { +- fprintf(config->global->errors, "Metalink: parsing (%s) WARNING " +- "(missing or invalid resource)\n", +- metalink_url); +- continue; +- } +- if(config->url_get || +- ((config->url_get = config->url_list) != NULL)) { +- /* there's a node here, if it already is filled-in continue to +- find an "empty" node */ +- while(config->url_get && (config->url_get->flags & GETOUT_URL)) +- config->url_get = config->url_get->next; +- } +- +- /* now there might or might not be an available node to fill in! */ +- +- if(config->url_get) +- /* existing node */ +- url = config->url_get; +- else +- /* there was no free node, create one! */ +- url = new_getout(config); +- +- if(url) { +- metalinkfile *mlfile = new_metalinkfile(*files); +- if(!mlfile) +- break; +- +- if(!mlfile->checksum) { +- warnings = TRUE; +- fprintf(config->global->errors, +- "Metalink: parsing (%s) WARNING (digest missing)\n", +- metalink_url); +- } +- /* Set name as url */ +- GetStr(&url->url, mlfile->filename); +- +- /* set flag metalink here */ +- url->flags |= GETOUT_URL | GETOUT_METALINK; +- +- if(config->metalinkfile_list) { +- config->metalinkfile_last->next = mlfile; +- config->metalinkfile_last = mlfile; +- } +- else { +- config->metalinkfile_list = config->metalinkfile_last = mlfile; +- } +- } +- } +- metalink_delete(metalink); +- return (warnings) ? -2 : 0; +-} +- +-size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb, +- void *userdata) +-{ +- struct per_transfer *per = userdata; +- struct OutStruct *outs = &per->outs; +- struct OperationConfig *config = outs->config; +- int rv; +- +- /* +- * Once that libcurl has called back tool_write_cb() the returned value +- * is checked against the amount that was intended to be written, if +- * it does not match then it fails with CURLE_WRITE_ERROR. So at this +- * point returning a value different from sz*nmemb indicates failure. +- */ +- const size_t failure = (sz && nmemb) ? 0 : 1; +- +- if(!config) +- return failure; +- +- rv = metalink_parse_update(outs->metalink_parser, buffer, sz * nmemb); +- if(rv == 0) +- return sz * nmemb; +- else { +- fprintf(config->global->errors, "Metalink: parsing FAILED\n"); +- return failure; +- } +-} +- +-/* +- * Returns nonzero if content_type includes mediatype. +- */ +-static int check_content_type(const char *content_type, const char *media_type) +-{ +- const char *ptr = content_type; +- size_t media_type_len = strlen(media_type); +- for(; *ptr && (*ptr == ' ' || *ptr == '\t'); ++ptr); +- if(!*ptr) { +- return 0; +- } +- return curl_strnequal(ptr, media_type, media_type_len) && +- (*(ptr + media_type_len) == '\0' || *(ptr + media_type_len) == ' ' || +- *(ptr + media_type_len) == '\t' || *(ptr + media_type_len) == ';'); +-} +- +-int check_metalink_content_type(const char *content_type) +-{ +- return check_content_type(content_type, "application/metalink+xml"); +-} +- +-int count_next_metalink_resource(metalinkfile *mlfile) +-{ +- int count = 0; +- metalink_resource *res; +- for(res = mlfile->resource; res; res = res->next, ++count); +- return count; +-} +- +-static void delete_metalink_checksum(metalink_checksum *chksum) +-{ +- if(chksum == NULL) { +- return; +- } +- Curl_safefree(chksum->digest); +- Curl_safefree(chksum); +-} +- +-static void delete_metalink_resource(metalink_resource *res) +-{ +- if(res == NULL) { +- return; +- } +- Curl_safefree(res->url); +- Curl_safefree(res); +-} +- +-void delete_metalinkfile(metalinkfile *mlfile) +-{ +- metalink_resource *res; +- if(mlfile == NULL) { +- return; +- } +- Curl_safefree(mlfile->filename); +- delete_metalink_checksum(mlfile->checksum); +- for(res = mlfile->resource; res;) { +- metalink_resource *next; +- next = res->next; +- delete_metalink_resource(res); +- res = next; +- } +- Curl_safefree(mlfile); +-} +- +-void clean_metalink(struct OperationConfig *config) +-{ +- if(config) { +- while(config->metalinkfile_list) { +- metalinkfile *mlfile = config->metalinkfile_list; +- config->metalinkfile_list = config->metalinkfile_list->next; +- delete_metalinkfile(mlfile); +- } +- config->metalinkfile_last = 0; +- } +-} +- +-void metalink_cleanup(void) +-{ +-#ifdef HAVE_NSS_CONTEXT +- if(nss_context) { +- NSS_ShutdownContext(nss_context); +- nss_context = NULL; +- } +-#endif +-} +- +-#endif /* USE_METALINK */ +diff --git a/src/tool_metalink.h b/src/tool_metalink.h +deleted file mode 100644 +index f5ec306..0000000 +--- a/src/tool_metalink.h ++++ /dev/null +@@ -1,171 +0,0 @@ +-#ifndef HEADER_CURL_TOOL_METALINK_H +-#define HEADER_CURL_TOOL_METALINK_H +-/*************************************************************************** +- * _ _ ____ _ +- * Project ___| | | | _ \| | +- * / __| | | | |_) | | +- * | (__| |_| | _ <| |___ +- * \___|\___/|_| \_\_____| +- * +- * Copyright (C) 1998 - 2014, 2019, Daniel Stenberg, , et al. +- * +- * This software is licensed as described in the file COPYING, which +- * you should have received as part of this distribution. The terms +- * are also available at https://curl.haxx.se/docs/copyright.html. +- * +- * You may opt to use, copy, modify, merge, publish, distribute and/or sell +- * copies of the Software, and permit persons to whom the Software is +- * furnished to do so, under the terms of the COPYING file. +- * +- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +- * KIND, either express or implied. +- * +- ***************************************************************************/ +-#include "tool_setup.h" +-#include "tool_sdecls.h" +- +-struct GlobalConfig; +-struct OperationConfig; +- +-/* returns 1 for success, 0 otherwise (we use OpenSSL *_Init fncs directly) */ +-typedef int (* Curl_digest_init_func)(void *context); +- +-typedef void (* Curl_digest_update_func)(void *context, +- const unsigned char *data, +- unsigned int len); +-typedef void (* Curl_digest_final_func)(unsigned char *result, void *context); +- +-typedef struct { +- Curl_digest_init_func digest_init; /* Initialize context procedure */ +- Curl_digest_update_func digest_update; /* Update context with data */ +- Curl_digest_final_func digest_final; /* Get final result procedure */ +- unsigned int digest_ctxtsize; /* Context structure size */ +- unsigned int digest_resultlen; /* Result length (bytes) */ +-} digest_params; +- +-typedef struct { +- const digest_params *digest_hash; /* Hash function definition */ +- void *digest_hashctx; /* Hash function context */ +-} digest_context; +- +-digest_context * Curl_digest_init(const digest_params *dparams); +-int Curl_digest_update(digest_context *context, +- const unsigned char *data, +- unsigned int len); +-int Curl_digest_final(digest_context *context, unsigned char *result); +- +-typedef struct { +- const char *hash_name; +- const digest_params *dparams; +-} metalink_digest_def; +- +-typedef struct { +- const char *alias_name; +- const metalink_digest_def *digest_def; +-} metalink_digest_alias; +- +-typedef struct metalink_checksum { +- const metalink_digest_def *digest_def; +- /* raw digest value, not ascii hex digest */ +- unsigned char *digest; +-} metalink_checksum; +- +-typedef struct metalink_resource { +- struct metalink_resource *next; +- char *url; +-} metalink_resource; +- +-typedef struct metalinkfile { +- struct metalinkfile *next; +- char *filename; +- metalink_checksum *checksum; +- metalink_resource *resource; +-} metalinkfile; +- +-#ifdef USE_METALINK +- +-/* +- * curl requires libmetalink 0.1.0 or newer +- */ +-#define CURL_REQ_LIBMETALINK_MAJOR 0 +-#define CURL_REQ_LIBMETALINK_MINOR 1 +-#define CURL_REQ_LIBMETALINK_PATCH 0 +- +-#define CURL_REQ_LIBMETALINK_VERS ((CURL_REQ_LIBMETALINK_MAJOR * 10000) + \ +- (CURL_REQ_LIBMETALINK_MINOR * 100) + \ +- CURL_REQ_LIBMETALINK_PATCH) +- +-extern const digest_params MD5_DIGEST_PARAMS[1]; +-extern const digest_params SHA1_DIGEST_PARAMS[1]; +-extern const digest_params SHA256_DIGEST_PARAMS[1]; +- +-#include +- +-/* +- * Counts the resource in the metalinkfile. +- */ +-int count_next_metalink_resource(metalinkfile *mlfile); +- +-void delete_metalinkfile(metalinkfile *mlfile); +-void clean_metalink(struct OperationConfig *config); +- +-/* +- * Performs final parse operation and extracts information from +- * Metalink and creates metalinkfile structs. +- * +- * This function returns 0 if it succeeds without warnings, or one of +- * the following negative error codes: +- * +- * -1: Parsing failed; or no file is found +- * -2: Parsing succeeded with some warnings. +- */ +-int parse_metalink(struct OperationConfig *config, struct OutStruct *outs, +- const char *metalink_url); +- +-/* +- * Callback function for CURLOPT_WRITEFUNCTION +- */ +-size_t metalink_write_cb(void *buffer, size_t sz, size_t nmemb, +- void *userdata); +- +-/* +- * Returns nonzero if content_type includes "application/metalink+xml" +- * media-type. The check is done in case-insensitive manner. +- */ +-int check_metalink_content_type(const char *content_type); +- +-/* +- * Check checksum of file denoted by filename. +- * +- * This function returns 1 if the checksum matches or one of the +- * following integers: +- * +- * 0: +- * Checksum didn't match. +- * -1: +- * Could not open file; or could not read data from file. +- * -2: +- * No checksum in Metalink supported, hash algorithm not available, or +- * Metalink does not contain checksum. +- */ +-int metalink_check_hash(struct GlobalConfig *config, +- metalinkfile *mlfile, +- const char *filename); +- +-/* +- * Release resources allocated at global scope. +- */ +-void metalink_cleanup(void); +- +-#else /* USE_METALINK */ +- +-#define count_next_metalink_resource(x) 0 +-#define delete_metalinkfile(x) (void)x +-#define clean_metalink(x) (void)x +- +-/* metalink_cleanup() takes no arguments */ +-#define metalink_cleanup() Curl_nop_stmt +- +-#endif /* USE_METALINK */ +- +-#endif /* HEADER_CURL_TOOL_METALINK_H */ +diff --git a/src/tool_operate.c b/src/tool_operate.c +index 2bee934..acd22a9 100644 +--- a/src/tool_operate.c ++++ b/src/tool_operate.c +@@ -64,7 +64,6 @@ + #include "tool_homedir.h" + #include "tool_libinfo.h" + #include "tool_main.h" +-#include "tool_metalink.h" + #include "tool_msgs.h" + #include "tool_operate.h" + #include "tool_operhlp.h" +@@ -394,35 +393,6 @@ static CURLcode post_per_transfer(struct GlobalConfig *global, + } + } + +-#ifdef USE_METALINK +- if(per->metalink && !per->metalink_next_res) +- fprintf(global->errors, "Metalink: fetching (%s) from (%s) OK\n", +- per->mlfile->filename, per->this_url); +- +- if(!per->metalink && config->use_metalink && result == CURLE_OK) { +- int rv = parse_metalink(config, outs, per->this_url); +- if(!rv) { +- fprintf(config->global->errors, "Metalink: parsing (%s) OK\n", +- per->this_url); +- } +- else if(rv == -1) +- fprintf(config->global->errors, "Metalink: parsing (%s) FAILED\n", +- per->this_url); +- } +- else if(per->metalink && result == CURLE_OK && !per->metalink_next_res) { +- int rv; +- (void)fflush(outs->stream); +- rv = metalink_check_hash(global, per->mlfile, outs->filename); +- if(!rv) +- per->metalink_next_res = 1; +- } +-#endif /* USE_METALINK */ +- +-#ifdef USE_METALINK +- if(outs->metalink_parser) +- metalink_parser_context_delete(outs->metalink_parser); +-#endif /* USE_METALINK */ +- + if(outs->is_cd_filename && outs->stream && !global->mute && + outs->filename) + printf("curl: Saved to filename '%s'\n", outs->filename); +@@ -579,37 +549,7 @@ static CURLcode post_per_transfer(struct GlobalConfig *global, + return CURLE_OK; + } + } /* if retry_numretries */ +- else if(per->metalink) { +- /* Metalink: Decide to try the next resource or not. Try the next resource +- if download was not successful. */ +- long response; +- if(CURLE_OK == result) { +- /* TODO We want to try next resource when download was +- not successful. How to know that? */ +- char *effective_url = NULL; +- curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective_url); +- if(effective_url && +- curl_strnequal(effective_url, "http", 4)) { +- /* This was HTTP(S) */ +- curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); +- if(response != 200 && response != 206) { +- per->metalink_next_res = 1; +- fprintf(global->errors, +- "Metalink: fetching (%s) from (%s) FAILED " +- "(HTTP status code %ld)\n", +- per->mlfile->filename, per->this_url, response); +- } +- } +- } +- else { +- per->metalink_next_res = 1; +- fprintf(global->errors, +- "Metalink: fetching (%s) from (%s) FAILED (%s)\n", +- per->mlfile->filename, per->this_url, +- curl_easy_strerror(result)); +- } +- } +- ++ + if((global->progressmode == CURL_PROGRESS_BAR) && + per->progressbar.calls) + /* if the custom progress bar has been displayed, we output a +@@ -692,7 +632,6 @@ static CURLcode single_transfer(struct GlobalConfig *global, + { + CURLcode result = CURLE_OK; + struct getout *urlnode; +- metalinkfile *mlfile_last = NULL; + bool orig_noprogress = global->noprogress; + bool orig_isatty = global->isatty; + struct State *state = &config->state; +@@ -734,24 +673,8 @@ static CURLcode single_transfer(struct GlobalConfig *global, + while(config->state.urlnode) { + char *infiles; /* might be a glob pattern */ + URLGlob *inglob = state->inglob; +- bool metalink = FALSE; /* metalink download? */ +- metalinkfile *mlfile; +- metalink_resource *mlres; + + urlnode = config->state.urlnode; +- if(urlnode->flags & GETOUT_METALINK) { +- metalink = 1; +- if(mlfile_last == NULL) { +- mlfile_last = config->metalinkfile_list; +- } +- mlfile = mlfile_last; +- mlfile_last = mlfile_last->next; +- mlres = mlfile->resource; +- } +- else { +- mlfile = NULL; +- mlres = NULL; +- } + + /* urlnode->url is the full URL (it might be NULL) */ + +@@ -813,12 +736,7 @@ static CURLcode single_transfer(struct GlobalConfig *global, + } + + if(!state->urlnum) { +- if(metalink) { +- /* For Metalink download, we don't use glob. Instead we use +- the number of resources as urlnum. */ +- urlnum = count_next_metalink_resource(mlfile); +- } +- else if(!config->globoff) { ++ if(!config->globoff) { + /* Unless explicitly shut off, we expand '{...}' and '[...]' + expressions and return total number of URLs in pattern set */ + result = glob_url(&state->urls, urlnode->url, &state->urlnum, +@@ -974,51 +892,33 @@ static CURLcode single_transfer(struct GlobalConfig *global, + outs->stream = stdout; + outs->config = config; + +- if(metalink) { +- /* For Metalink download, use name in Metalink file as +- filename. */ +- per->outfile = strdup(mlfile->filename); +- if(!per->outfile) { +- result = CURLE_OUT_OF_MEMORY; ++ if(state->urls) { ++ result = glob_next_url(&per->this_url, state->urls); ++ if(result) + break; +- } +- per->this_url = strdup(mlres->url); ++ } ++ else if(!state->li) { ++ per->this_url = strdup(urlnode->url); + if(!per->this_url) { + result = CURLE_OUT_OF_MEMORY; + break; + } +- per->mlfile = mlfile; + } +- else { +- if(state->urls) { +- result = glob_next_url(&per->this_url, state->urls); +- if(result) +- break; +- } +- else if(!state->li) { +- per->this_url = strdup(urlnode->url); +- if(!per->this_url) { +- result = CURLE_OUT_OF_MEMORY; +- break; +- } +- } +- else +- per->this_url = NULL; +- if(!per->this_url) +- break; ++ else ++ per->this_url = NULL; ++ if(!per->this_url) ++ break; + +- if(state->outfiles) { +- per->outfile = strdup(state->outfiles); +- if(!per->outfile) { +- result = CURLE_OUT_OF_MEMORY; +- break; +- } ++ if(state->outfiles) { ++ per->outfile = strdup(state->outfiles); ++ if(!per->outfile) { ++ result = CURLE_OUT_OF_MEMORY; ++ break; + } + } + + if(((urlnode->flags&GETOUT_USEREMOTE) || +- (per->outfile && strcmp("-", per->outfile))) && +- (metalink || !config->use_metalink)) { ++ (per->outfile && strcmp("-", per->outfile)))) { + + /* + * We have specified a file name to store the result in, or we have +@@ -1051,7 +951,7 @@ static CURLcode single_transfer(struct GlobalConfig *global, + /* Create the directory hierarchy, if not pre-existent to a multiple + file output call */ + +- if(config->create_dirs || metalink) { ++ if(config->create_dirs) { + result = create_dir_hierarchy(per->outfile, global->errors); + /* create_dir_hierarchy shows error upon CURLE_WRITE_ERROR */ + if(result) +@@ -1243,15 +1143,8 @@ static CURLcode single_transfer(struct GlobalConfig *global, + my_setopt(curl, CURLOPT_WRITEDATA, per); + my_setopt(curl, CURLOPT_INTERLEAVEDATA, per); + +- if(metalink || !config->use_metalink) +- /* what call to write */ +- my_setopt(curl, CURLOPT_WRITEFUNCTION, tool_write_cb); +-#ifdef USE_METALINK +- else +- /* Set Metalink specific write callback function to parse +- XML data progressively. */ +- my_setopt(curl, CURLOPT_WRITEFUNCTION, metalink_write_cb); +-#endif /* USE_METALINK */ ++ /* what call to write */ ++ my_setopt(curl, CURLOPT_WRITEFUNCTION, tool_write_cb); + + /* for uploads */ + input->config = config; +@@ -1969,23 +1862,6 @@ static CURLcode single_transfer(struct GlobalConfig *global, + my_setopt_str(curl, CURLOPT_ALTSVC, config->altsvc); + #endif + +-#ifdef USE_METALINK +- if(!metalink && config->use_metalink) { +- outs->metalink_parser = metalink_parser_context_new(); +- if(outs->metalink_parser == NULL) { +- result = CURLE_OUT_OF_MEMORY; +- break; +- } +- fprintf(config->global->errors, +- "Metalink: parsing (%s) metalink/XML...\n", per->this_url); +- } +- else if(metalink) +- fprintf(config->global->errors, +- "Metalink: fetching (%s) from (%s)...\n", +- mlfile->filename, per->this_url); +-#endif /* USE_METALINK */ +- +- per->metalink = metalink; + /* initialize retry vars for loop below */ + per->retry_sleep_default = (config->retry_delay) ? + config->retry_delay*1000L : RETRY_SLEEP_DEFAULT; /* ms */ +@@ -2220,9 +2096,6 @@ static CURLcode serial_transfers(struct GlobalConfig *global, + bailout = TRUE; + } + +- /* Release metalink related resources here */ +- delete_metalinkfile(per->mlfile); +- + per = del_per_transfer(per); + + if(bailout) +@@ -2390,8 +2263,6 @@ static CURLcode run_all_transfers(struct GlobalConfig *global, + /* Free list of given URLs */ + clean_getout(per->config); + +- /* Release metalink related resources here */ +- clean_metalink(per->config); + per = del_per_transfer(per); + } + +diff --git a/src/tool_operate.h b/src/tool_operate.h +index 39227c0..ed1e44e 100644 +--- a/src/tool_operate.h ++++ b/src/tool_operate.h +@@ -36,10 +36,6 @@ struct per_transfer { + long retry_sleep_default; + long retry_sleep; + struct timeval retrystart; +- bool metalink; /* nonzero for metalink download. */ +- bool metalink_next_res; +- metalinkfile *mlfile; +- metalink_resource *mlres; + char *this_url; + char *outfile; + bool infdopen; /* TRUE if infd needs closing */ +diff --git a/src/tool_operhlp.c b/src/tool_operhlp.c +index 8a9b7c9..64d153d 100644 +--- a/src/tool_operhlp.c ++++ b/src/tool_operhlp.c +@@ -31,7 +31,6 @@ + #include "tool_convert.h" + #include "tool_doswin.h" + #include "tool_operhlp.h" +-#include "tool_metalink.h" + + #include "memdebug.h" /* keep this as LAST include */ + +diff --git a/src/tool_sdecls.h b/src/tool_sdecls.h +index 562fef8..369885d 100644 +--- a/src/tool_sdecls.h ++++ b/src/tool_sdecls.h +@@ -22,9 +22,6 @@ + * + ***************************************************************************/ + #include "tool_setup.h" +-#ifdef USE_METALINK +-# include +-#endif /* USE_METALINK */ + + /* + * OutStruct variables keep track of information relative to curl's +@@ -58,8 +55,6 @@ + * 'init' member holds original file size or offset at which truncation is + * taking place. Always zero unless appending to a non-empty regular file. + * +- * 'metalink_parser' member is a pointer to Metalink XML parser +- * context. + */ + + struct OutStruct { +@@ -113,7 +108,6 @@ struct getout { + #define GETOUT_USEREMOTE (1<<2) /* use remote file name locally */ + #define GETOUT_UPLOAD (1<<3) /* if set, -T has been used */ + #define GETOUT_NOUPLOAD (1<<4) /* if set, -T "" has been used */ +-#define GETOUT_METALINK (1<<5) /* set when Metalink download */ + + /* + * 'trace' enumeration represents curl's output look'n feel possibilities. +diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc +index c005d5f..4fb041e 100644 +--- a/tests/data/Makefile.inc ++++ b/tests/data/Makefile.inc +@@ -198,9 +198,9 @@ test1800 test1801 \ + \ + test1900 test1901 test1902 test1903 test1904 test1905 test1906 test1907 \ + \ +-test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \ +-test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \ +-test2016 test2017 test2018 test2019 test2020 test2021 test2022 test2023 \ ++test2000 test2001 test2002 test2003 test2004 \ ++\ ++ test2023 \ + test2024 test2025 test2026 test2027 test2028 test2029 test2030 test2031 \ + test2032 test2033 test2034 test2035 test2036 test2037 test2038 test2039 \ + test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 \ +diff --git a/tests/data/test2005 b/tests/data/test2005 +deleted file mode 100644 +index f78b4be..0000000 +--- a/tests/data/test2005 ++++ /dev/null +@@ -1,93 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 37 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2005; charset=funny; option=strange +-Funny-head: yesyes +- +-Data delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, HTTP resource +- +- +---metalink file://%PWD/log/test2005.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- a430d26389c69b7a245a9ad692cf20b4dc026fb7c2ff8a2c164c49a77130d6d9 +- +- +- http://%HOSTIP:%HTTPPORT/2005 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2005 log/name2005 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /2005 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Accept: */* +- +- +- +-Data delivered from an HTTP resource +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2005.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2005.metalink) OK +-Metalink: fetching (log/download2005) from (http://%HOSTIP:%HTTPPORT/2005)... +-Metalink: fetching (log/download2005) from (http://%HOSTIP:%HTTPPORT/2005) OK +-Metalink: validating (log/download2005)... +-Metalink: validating (log/download2005) [sha-256] OK +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2006 b/tests/data/test2006 +deleted file mode 100644 +index 1f59717..0000000 +--- a/tests/data/test2006 ++++ /dev/null +@@ -1,116 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +-FILE +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 14:49:01 GMT +-Server: test-server/fake +-Content-Length: 42 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2006; charset=funny; option=strange +-Funny-head: yesyes +- +-Some data delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +-# This relies on the debug feature to allow us to set directory to store the +-# -O output in, using the CURL_TESTDIR variable. This test might use it upon +-# failure only, successful execution won't actually use it. +- +-debug +-file +-Metalink +- +- +-http +- +- +-Metalink local XML file, HTTP resource, using -O -D file +- +- +-CURL_TESTDIR=%PWD/log +- +- +---metalink file://%PWD/log/test2006.metalink -O -D log/heads2006 +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- we-only-check-the-strongest-hash-provided +- 319cb6be756734b7ff689628ca3265580cdae6a0e38f42d4ac612ff4fba143b0 +- +- +- http://%HOSTIP:%HTTPPORT/2006 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2006 log/name2006 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /2006 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Accept: */* +- +- +- +-Some data delivered from an HTTP resource +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 14:49:01 GMT +-Server: test-server/fake +-Content-Length: 42 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2006; charset=funny; option=strange +-Funny-head: yesyes +- +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2006.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2006.metalink) OK +-Metalink: fetching (log/download2006) from (http://%HOSTIP:%HTTPPORT/2006)... +-Metalink: fetching (log/download2006) from (http://%HOSTIP:%HTTPPORT/2006) OK +-Metalink: validating (log/download2006)... +-Metalink: validating (log/download2006) [sha-256] OK +- +- +-s/Last-Modified:.*// +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2007 b/tests/data/test2007 +deleted file mode 100644 +index a8e5f1b..0000000 +--- a/tests/data/test2007 ++++ /dev/null +@@ -1,117 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +--J +-FILE +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 14:50:02 GMT +-Server: test-server/fake +-Content-Length: 42 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2007; charset=funny; option=strange +-Funny-head: yesyes +- +-Something delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +-# This relies on the debug feature to allow us to set directory to store the +-# -O and -J output in, using the CURL_TESTDIR variable. This test might use +-# it upon failure only, successful execution won't actually use it. +- +-debug +-file +-Metalink +- +- +-http +- +- +-Metalink local XML file, HTTP resource, using -O -J -D file +- +- +-CURL_TESTDIR=%PWD/log +- +- +---metalink file://%PWD/log/test2007.metalink -J -O -D log/heads2007 +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- we-only-check-the-strongest-hash-provided +- 52899e30f80e3490632d505653204e1fb5b02bda141048704ce9a0ed00b8a3f5 +- +- +- http://%HOSTIP:%HTTPPORT/2007 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2007 log/name2007 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /2007 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Accept: */* +- +- +- +-Something delivered from an HTTP resource +- +- +-s/Last-Modified:.*// +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 14:50:02 GMT +-Server: test-server/fake +-Content-Length: 42 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2007; charset=funny; option=strange +-Funny-head: yesyes +- +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2007.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2007.metalink) OK +-Metalink: fetching (log/download2007) from (http://%HOSTIP:%HTTPPORT/2007)... +-Metalink: fetching (log/download2007) from (http://%HOSTIP:%HTTPPORT/2007) OK +-Metalink: validating (log/download2007)... +-Metalink: validating (log/download2007) [sha-256] OK +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2008 b/tests/data/test2008 +deleted file mode 100644 +index 1a00332..0000000 +--- a/tests/data/test2008 ++++ /dev/null +@@ -1,109 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +-FILE +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 15:23:48 GMT +-Server: test-server/fake +-Content-Length: 43 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2008; charset=funny; option=strange +-Funny-head: yesyes +- +-Some stuff delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-file +-Metalink +- +- +-http +- +- +-Metalink local XML file, HTTP resource, using -o fname -D file +- +- +---metalink file://%PWD/log/test2008.metalink -o log/outfile2008 -D log/heads2008 +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- we-only-check-the-strongest-hash-provided +- 711b1b566b536c5baae9b36f2f5c1830a7c8ff126d1afa2febc5b59f8d0aab54 +- +- +- http://%HOSTIP:%HTTPPORT/2008 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2008 log/name2008 log/outfile2008 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /2008 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Accept: */* +- +- +- +-Some stuff delivered from an HTTP resource +- +- +-s/Last-Modified:.*// +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 15:23:48 GMT +-Server: test-server/fake +-Content-Length: 43 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2008; charset=funny; option=strange +-Funny-head: yesyes +- +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2008.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2008.metalink) OK +-Metalink: fetching (log/download2008) from (http://%HOSTIP:%HTTPPORT/2008)... +-Metalink: fetching (log/download2008) from (http://%HOSTIP:%HTTPPORT/2008) OK +-Metalink: validating (log/download2008)... +-Metalink: validating (log/download2008) [sha-256] OK +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2009 b/tests/data/test2009 +deleted file mode 100644 +index 08308d0..0000000 +--- a/tests/data/test2009 ++++ /dev/null +@@ -1,110 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +--J +-FILE +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 16:27:17 GMT +-Server: test-server/fake +-Content-Length: 46 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2009; charset=funny; option=strange +-Funny-head: yesyes +- +-Some contents delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-file +-Metalink +- +- +-http +- +- +-Metalink local XML file, HTTP resource, using -o fname -J -D file +- +- +---metalink file://%PWD/log/test2009.metalink -J -o log/outfile2009 -D log/heads2009 +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- we-only-check-the-strongest-hash-provided +- e4c5b83384ba7d5f8e201d61747a14f29baacd7dfadce0fbd56661db4bba72b2 +- +- +- http://%HOSTIP:%HTTPPORT/2009 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2009 log/name2009 log/outfile2009 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /2009 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Accept: */* +- +- +- +-Some contents delivered from an HTTP resource +- +- +-s/Last-Modified:.*// +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 16:27:17 GMT +-Server: test-server/fake +-Content-Length: 46 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2009; charset=funny; option=strange +-Funny-head: yesyes +- +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2009.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2009.metalink) OK +-Metalink: fetching (log/download2009) from (http://%HOSTIP:%HTTPPORT/2009)... +-Metalink: fetching (log/download2009) from (http://%HOSTIP:%HTTPPORT/2009) OK +-Metalink: validating (log/download2009)... +-Metalink: validating (log/download2009) [sha-256] OK +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2010 b/tests/data/test2010 +deleted file mode 100644 +index 068c481..0000000 +--- a/tests/data/test2010 ++++ /dev/null +@@ -1,109 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +-FILE +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 17:37:27 GMT +-Server: test-server/fake +-Content-Length: 41 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2010; charset=funny; option=strange +-Funny-head: yesyes +- +-Contents delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-file +-Metalink +- +- +-http +- +- +-Metalink local XML file, HTTP resource, using -o fname -D file +- +- +---metalink file://%PWD/log/test2010.metalink -o log/outfile2010 -D log/heads2010 +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- we-only-check-the-strongest-hash-provided +- 19dcb4e2a99b9cd02c30b1ed6c55869b7ef8cda9f985648909c48a6dbb54356c +- +- +- http://%HOSTIP:%HTTPPORT/2010 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2010 log/name2010 log/outfile2010 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /2010 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Accept: */* +- +- +- +-Contents delivered from an HTTP resource +- +- +-s/Last-Modified:.*// +- +- +-HTTP/1.1 200 OK +-Date: Thu, 21 Jun 2012 17:37:27 GMT +-Server: test-server/fake +-Content-Length: 41 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2010; charset=funny; option=strange +-Funny-head: yesyes +- +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2010.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2010.metalink) OK +-Metalink: fetching (log/download2010) from (http://%HOSTIP:%HTTPPORT/2010)... +-Metalink: fetching (log/download2010) from (http://%HOSTIP:%HTTPPORT/2010) OK +-Metalink: validating (log/download2010)... +-Metalink: validating (log/download2010) [sha-256] OK +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2011 b/tests/data/test2011 +deleted file mode 100644 +index a845023..0000000 +--- a/tests/data/test2011 ++++ /dev/null +@@ -1,93 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 37 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2011; charset=funny; option=strange +-Funny-head: yesyes +- +-Data delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, HTTP resource, hash mismatch +- +- +---metalink file://%PWD/log/test2011.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- badbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadbadb +- +- +- http://%HOSTIP:%HTTPPORT/2011 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2011 log/name2011 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /2011 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Accept: */* +- +- +- +-Data delivered from an HTTP resource +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2011.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2011.metalink) OK +-Metalink: fetching (log/download2011) from (http://%HOSTIP:%HTTPPORT/2011)... +-Metalink: fetching (log/download2011) from (http://%HOSTIP:%HTTPPORT/2011) OK +-Metalink: validating (log/download2011)... +-Metalink: validating (log/download2011) [sha-256] FAILED (digest mismatch) +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2012 b/tests/data/test2012 +deleted file mode 100644 +index 6751269..0000000 +--- a/tests/data/test2012 ++++ /dev/null +@@ -1,92 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 46 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2012; charset=funny; option=strange +-Funny-head: yesyes +- +-Some contents delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, HTTP resource, without hash +- +- +---metalink file://%PWD/log/test2012.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- +- +- http://%HOSTIP:%HTTPPORT/2012 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2012 log/name2012 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +-^User-Agent:.* +- +- +-GET /2012 HTTP/1.1 +-Host: %HOSTIP:%HTTPPORT +-Accept: */* +- +- +- +-Some contents delivered from an HTTP resource +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2012.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2012.metalink) WARNING (digest missing) +-Metalink: fetching (log/download2012) from (http://%HOSTIP:%HTTPPORT/2012)... +-Metalink: fetching (log/download2012) from (http://%HOSTIP:%HTTPPORT/2012) OK +-Metalink: validating (log/download2012)... +-Metalink: validating (log/download2012) FAILED (digest missing) +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2013 b/tests/data/test2013 +deleted file mode 100644 +index f4d0c24..0000000 +--- a/tests/data/test2013 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2013; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix absolute path +- +- +---metalink file://%PWD/log/test2013.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2013 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2013 log/name2013 /tmp/download2013 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2013.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2013.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2013.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2014 b/tests/data/test2014 +deleted file mode 100644 +index 65d2ec7..0000000 +--- a/tests/data/test2014 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2014; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix path relative to current +- +- +---metalink file://%PWD/log/test2014.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2014 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2014 log/name2014 log/download2014 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2014.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2014.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2014.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2015 b/tests/data/test2015 +deleted file mode 100644 +index d356f88..0000000 +--- a/tests/data/test2015 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2015; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix path relative to upper +- +- +---metalink file://%PWD/log/test2015.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2015 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2015 log/name2015 log/download2015 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2015.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2015.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2015.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2016 b/tests/data/test2016 +deleted file mode 100644 +index ff2862d..0000000 +--- a/tests/data/test2016 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2016; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix path traversal +- +- +---metalink file://%PWD/log/test2016.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2016 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2016 log/name2016 log/download2016 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2016.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2016.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2016.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2017 b/tests/data/test2017 +deleted file mode 100644 +index 11c71c3..0000000 +--- a/tests/data/test2017 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2017; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix home path traversal +- +- +---metalink file://%PWD/log/test2017.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2017 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2017 log/name2017 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2017.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2017.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2017.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2018 b/tests/data/test2018 +deleted file mode 100644 +index 9fb433d..0000000 +--- a/tests/data/test2018 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2018; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix questionable file name I +- +- +---metalink file://%PWD/log/test2018.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2018 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2018 log/name2018 log/.download2018 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2018.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2018.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2018.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2019 b/tests/data/test2019 +deleted file mode 100644 +index abd8cad..0000000 +--- a/tests/data/test2019 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2019; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix questionable file name II +- +- +---metalink file://%PWD/log/test2019.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2019 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2019 log/name2019 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2019.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2019.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2019.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2020 b/tests/data/test2020 +deleted file mode 100644 +index 584f6df..0000000 +--- a/tests/data/test2020 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2020; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix questionable file name III +- +- +---metalink file://%PWD/log/test2020.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2020 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2020 log/name2020 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2020.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2020.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2020.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2021 b/tests/data/test2021 +deleted file mode 100644 +index b0921d4..0000000 +--- a/tests/data/test2021 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2021; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix questionable file name IV +- +- +---metalink file://%PWD/log/test2021.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2021 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2021 log/name2021 log/download2021 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2021.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2021.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2021.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/data/test2022 b/tests/data/test2022 +deleted file mode 100644 +index e904473..0000000 +--- a/tests/data/test2022 ++++ /dev/null +@@ -1,78 +0,0 @@ +- +- +- +-Metalink +-HTTP +-HTTP GET +- +- +- +-# +-# Server-side +- +- +-HTTP/1.1 200 OK +-Date: Wed, 20 Jun 2012 14:49:00 GMT +-Server: test-server/fake +-Content-Length: 56 +-Connection: close +-Content-Type: text/html +-Content-Disposition: filename=name2022; charset=funny; option=strange +-Funny-head: yesyes +- +-Data that should not be delivered from an HTTP resource +- +- +- +-# +-# Client-side +- +- +-http +- +- +-file +-Metalink +- +- +-Metalink local XML file, attempt Unix questionable file name V +- +- +---metalink file://%PWD/log/test2022.metalink +- +-# local metalink file written before test command runs +- +- +- +- +- +- +- c7d03debe90ca29492203ea921d76941fa98640cf3b744f2a16c9b58465eab82 +- +- +- http://%HOSTIP:%HTTPPORT/2022 +- +- +- +- +- +- +-perl %SRCDIR/libtest/notexists.pl log/2022 log/name2022 log/download2022 +- +- +- +-# +-# Verify data after the test has been "shot" +- +- +- +- +-Metalink: parsing (file://%PWD/log/test2022.metalink) metalink/XML... +-Metalink: parsing (file://%PWD/log/test2022.metalink) WARNING (missing or invalid file name) +-Metalink: parsing (file://%PWD/log/test2022.metalink) FAILED +- +- +-$_ = '' if (($_ !~ /^Metalink: /) && ($_ !~ /error/i) && ($_ !~ /warn/i)) +- +- +- +diff --git a/tests/libtest/test1013.pl b/tests/libtest/test1013.pl +index b680273..a2db71a 100755 +--- a/tests/libtest/test1013.pl ++++ b/tests/libtest/test1013.pl +@@ -23,7 +23,7 @@ $curl_protocols =~ /\w+: (.*)$/; + @curl = split / /,$1; + + # These features are not supported by curl-config +-@curl = grep(!/^(Debug|TrackMemory|Metalink|Largefile|CharConv)$/i, @curl); ++@curl = grep(!/^(Debug|TrackMemory|Largefile|CharConv)$/i, @curl); + @curl = sort @curl; + + # Read the output of curl-config +diff --git a/tests/runtests.pl b/tests/runtests.pl +index 27f62ed..9bb2627 100755 +--- a/tests/runtests.pl ++++ b/tests/runtests.pl +@@ -231,7 +231,6 @@ my $has_kerberos; # set if libcurl is built with Kerberos support + my $has_spnego; # set if libcurl is built with SPNEGO support + my $has_charconv; # set if libcurl is built with CharConv support + my $has_tls_srp; # set if libcurl is built with TLS-SRP support +-my $has_metalink; # set if curl is built with Metalink support + my $has_http2; # set if libcurl is built with HTTP2 support + my $has_crypto; # set if libcurl is built with cryptographic support + my $has_cares; # set if built with c-ares +@@ -2625,7 +2624,6 @@ sub setupfeatures { + $feature{"getrlimit"} = $has_getrlimit; + $feature{"crypto"} = $has_crypto; + $feature{"TLS-SRP"} = $has_tls_srp; +- $feature{"Metalink"} = $has_metalink; + $feature{"http/2"} = $has_http2; + $feature{"threaded-resolver"} = $has_threadedres; + $feature{"PSL"} = $has_psl; +@@ -2855,10 +2853,6 @@ sub checksystem { + # TLS-SRP enabled + $has_tls_srp=1; + } +- if($feat =~ /Metalink/i) { +- # Metalink enabled +- $has_metalink=1; +- } + if($feat =~ /PSL/i) { + # PSL enabled + $has_psl=1; +diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc +index 45278ba..95b8d94 100644 +--- a/tests/unit/Makefile.inc ++++ b/tests/unit/Makefile.inc +@@ -47,9 +47,9 @@ unit1330_SOURCES = unit1330.c $(UNITFILES) + unit1330_CPPFLAGS = $(AM_CPPFLAGS) + + unit1394_SOURCES = unit1394.c $(UNITFILES) +-unit1394_CPPFLAGS = $(AM_CPPFLAGS) $(LIBMETALINK_CPPFLAGS) +-unit1394_LDADD = @LIBMETALINK_LIBS@ $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@ +-unit1394_LDFLAGS = @LIBMETALINK_LDFLAGS@ $(top_builddir)/src/libcurltool.la ++unit1394_CPPFLAGS = $(AM_CPPFLAGS) ++unit1394_LDADD = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@ ++unit1394_LDFLAGS = $(top_builddir)/src/libcurltool.la + unit1394_LIBS = + + unit1395_SOURCES = unit1395.c $(UNITFILES) +@@ -80,7 +80,7 @@ unit1603_SOURCES = unit1603.c $(UNITFILES) + unit1603_CPPFLAGS = $(AM_CPPFLAGS) + + unit1604_SOURCES = unit1604.c $(UNITFILES) +-unit1604_CPPFLAGS = $(AM_CPPFLAGS) $(LIBMETALINK_CPPFLAGS) ++unit1604_CPPFLAGS = $(AM_CPPFLAGS) + + unit1605_SOURCES = unit1605.c $(UNITFILES) + unit1605_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/debian/patches/0026-42-fix-curl-Fix-CVE-2023-38546-cookie-injection-vuln.patch b/debian/patches/0026-42-fix-curl-Fix-CVE-2023-38546-cookie-injection-vuln.patch new file mode 100644 index 0000000000000000000000000000000000000000..25ab5120f9fa15ffd0e394229a0b918c81e12e87 --- /dev/null +++ b/debian/patches/0026-42-fix-curl-Fix-CVE-2023-38546-cookie-injection-vuln.patch @@ -0,0 +1,115 @@ +From: gfc +Date: Sat, 7 Nov 2026 07:57:56 +0000 +Subject: !42 fix(curl): Fix CVE-2023-38546 cookie injection vulnerability + (I8GOAT) + +Merge pull request !42 from universalcollapse/openkylin/yangtze +--- + lib/cookie.c | 13 +------------ + lib/cookie.h | 7 ++----- + lib/easy.c | 2 +- + 3 files changed, 4 insertions(+), 18 deletions(-) + +diff --git a/lib/cookie.c b/lib/cookie.c +index ff3e200..63e80e9 100644 +--- a/lib/cookie.c ++++ b/lib/cookie.c +@@ -112,7 +112,6 @@ static void freecookie(struct Cookie *co) + free(co->name); + free(co->value); + free(co->maxage); +- free(co->version); + free(co); + } + +@@ -660,11 +659,7 @@ Curl_cookie_add(struct Curl_easy *data, + } + } + else if(strcasecompare("version", name)) { +- strstore(&co->version, whatptr); +- if(!co->version) { +- badcookie = TRUE; +- break; +- } ++ /* just ignore */ + } + else if(strcasecompare("max-age", name)) { + /* Defined in RFC2109: +@@ -1069,7 +1064,6 @@ Curl_cookie_add(struct Curl_easy *data, + free(clist->path); + free(clist->spath); + free(clist->expirestr); +- free(clist->version); + free(clist->maxage); + + *clist = *co; /* then store all the new data */ +@@ -1138,9 +1132,6 @@ struct CookieInfo *Curl_cookie_init(struct Curl_easy *data, + c = calloc(1, sizeof(struct CookieInfo)); + if(!c) + return NULL; /* failed to get memory */ +- c->filename = strdup(file?file:"none"); /* copy the name just in case */ +- if(!c->filename) +- goto fail; /* failed to get memory */ + } + else { + /* we got an already existing one, use that */ +@@ -1268,7 +1259,6 @@ static struct Cookie *dup_cookie(struct Cookie *src) + CLONE(name); + CLONE(value); + CLONE(maxage); +- CLONE(version); + d->expires = src->expires; + d->tailmatch = src->tailmatch; + d->secure = src->secure; +@@ -1484,7 +1474,6 @@ void Curl_cookie_cleanup(struct CookieInfo *c) + { + if(c) { + unsigned int i; +- free(c->filename); + for(i = 0; i < COOKIE_HASH_SIZE; i++) + Curl_cookie_freelist(c->cookies[i]); + free(c); /* free the base struct as well */ +diff --git a/lib/cookie.h b/lib/cookie.h +index b3865e6..a1c54d7 100644 +--- a/lib/cookie.h ++++ b/lib/cookie.h +@@ -36,8 +36,6 @@ struct Cookie { + char *expirestr; /* the plain text version */ + bool tailmatch; /* whether we do tail-matching of the domain name */ + +- /* RFC 2109 keywords. Version=1 means 2109-compliant cookie sending */ +- char *version; /* Version = */ + char *maxage; /* Max-Age = */ + + bool secure; /* whether the 'secure' keyword was used */ +@@ -54,15 +52,14 @@ struct Cookie { + #define COOKIE_PREFIX__SECURE (1<<0) + #define COOKIE_PREFIX__HOST (1<<1) + +-#define COOKIE_HASH_SIZE 256 ++#define COOKIE_HASH_SIZE 63 + + struct CookieInfo { + /* linked list of cookies we know of */ + struct Cookie *cookies[COOKIE_HASH_SIZE]; + +- char *filename; /* file we read from/write to */ + bool running; /* state info, for cookie adding information */ +- long numcookies; /* number of cookies in the "jar" */ ++ int numcookies; /* number of cookies in the "jar" */ + bool newsession; /* new session, discard session cookies on load */ + int lastct; /* last creation-time used in the jar */ + }; +diff --git a/lib/easy.c b/lib/easy.c +index 3b4c778..be07dc6 100644 +--- a/lib/easy.c ++++ b/lib/easy.c +@@ -841,7 +841,7 @@ struct Curl_easy *curl_easy_duphandle(struct Curl_easy *data) + /* If cookies are enabled in the parent handle, we enable them + in the clone as well! */ + outcurl->cookies = Curl_cookie_init(data, +- data->cookies->filename, ++ NULL, + outcurl->cookies, + data->set.cookiesession); + if(!outcurl->cookies) diff --git a/debian/patches/0027-39-fix-CVE-2024-2398-avoid-memory-leak-when-HTTP-2-s.patch b/debian/patches/0027-39-fix-CVE-2024-2398-avoid-memory-leak-when-HTTP-2-s.patch new file mode 100644 index 0000000000000000000000000000000000000000..927c18116f6eae6361f7f6fafb9955cde338824d --- /dev/null +++ b/debian/patches/0027-39-fix-CVE-2024-2398-avoid-memory-leak-when-HTTP-2-s.patch @@ -0,0 +1,69 @@ +From: gfc +Date: Sat, 7 Nov 2026 07:58:14 +0000 +Subject: !39 fix: CVE-2024-2398 avoid memory leak when HTTP/2 server push + exceeds max headers +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +Merge pull request !39 from 樊思琦/fix-memory-leak-http2-push +--- + lib/http2.c | 24 ++++++++++++++---------- + 1 file changed, 14 insertions(+), 10 deletions(-) + +diff --git a/lib/http2.c b/lib/http2.c +index 65f3513..85437f1 100644 +--- a/lib/http2.c ++++ b/lib/http2.c +@@ -126,6 +126,16 @@ static int http2_getsock(struct connectdata *conn, + return http2_perform_getsock(conn, socks); + } + ++static void free_push_headers(struct HTTP *stream) ++{ ++ size_t i; ++ for(i = 0; i < stream->push_headers_used; i++) ++ free(stream->push_headers[i]); ++ Curl_safefree(stream->push_headers); ++ stream->push_headers = NULL; ++ stream->push_headers_used = 0; ++} ++ + /* + * http2_stream_free() free HTTP2 stream related data + */ +@@ -134,11 +144,7 @@ static void http2_stream_free(struct HTTP *http) + if(http) { + Curl_add_buffer_free(&http->header_recvbuf); + Curl_add_buffer_free(&http->trailer_recvbuf); +- for(; http->push_headers_used > 0; --http->push_headers_used) { +- free(http->push_headers[http->push_headers_used - 1]); +- } +- free(http->push_headers); +- http->push_headers = NULL; ++ free_push_headers(http); + } + } + +@@ -557,11 +563,8 @@ static int push_promise(struct Curl_easy *data, + Curl_set_in_callback(data, false); + + /* free the headers again */ +- for(i = 0; ipush_headers_used; i++) +- free(stream->push_headers[i]); +- free(stream->push_headers); +- stream->push_headers = NULL; +- stream->push_headers_used = 0; ++ free_push_headers(stream); ++ + + if(rv) { + /* denied, kill off the new handle again */ +@@ -999,6 +1002,7 @@ static int on_header(nghttp2_session *session, const nghttp2_frame *frame, + stream->push_headers_alloc * sizeof(char *)); + if(!headp) { + stream->push_headers = NULL; ++ free_push_headers(stream); + return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE; + } + stream->push_headers = headp; diff --git a/debian/patches/series b/debian/patches/series index 0ec345be52046862c618b5c28f6bd7b91cc9c4bb..27bcb03b5c2637c289c2cab7191c53f71f94b35a 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -4,5 +4,24 @@ git_tls13_gnutls.patch 07_do-not-disable-debug-symbols.patch 08_enable-zsh.patch 11_omit-directories-from-config.patch -90_gnutls.patch -99_nss.patch +0009-update-debian-changelog.patch +0010-update-info.patch +0011-CVE-2022-43552-HTTP-Proxy-deny-use-after-free.patch +0012-openldap-replace-ldap_-prefix-on-private-functions.patch +0013-11-CVE-2023-27538.patch +0014-32.patch +0013-36-CVE-2024-8096.patch +0014-38-CVE-2023-28322.patch +0015-43-CVE-2023-27533-telnet-only-accept-option-argument.patch +0016-48-CVE-2023-46218-Fix-Cookie-mixed-case-PSL-bypass.patch +0017-53-fix-lib-fix-integer-overflow-in-gzip-header-parsi.patch +0018-45-Fix-CVE-2025-0725-Gzip-integer-overflow-with-old-.patch +0019-46-CVE-2023-38545-FIX.patch +0020-50-curl-backport-CVE-2023-28321-IDN-wildcard-match-f.patch +0021-51-CVE-2024-8096-add-basic-safety-validation-to-stre.patch +0022-56-CVE-2023-28321-fix-host-name-wildcard-checking.patch +0023-55-Fix-CVE-2021-22926-Secure-Transport-cert-name-fil.patch +0024-44-CVE-2025-9086-curl-Cookie.patch +0025-54-fix-CVE-2021-22922-Wrong-content-via-Metalink-not.patch +0026-42-fix-curl-Fix-CVE-2023-38546-cookie-injection-vuln.patch +0027-39-fix-CVE-2024-2398-avoid-memory-leak-when-HTTP-2-s.patch diff --git a/debian/rules b/debian/rules index f5a171b17768df1ab31ae493b0593d1769356b9b..548175c19a6140968fd993f8851be7d1d3b42db2 100755 --- a/debian/rules +++ b/debian/rules @@ -19,30 +19,26 @@ CONFIGURE_ARGS = -- --disable-dependency-tracking \ --includedir=/usr/include/$(DEB_HOST_MULTIARCH) \ --with-zsh-functions-dir=/usr/share/zsh/vendor-completions -# disable libssh2 on Ubuntu (see #888449) -ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes) - CONFIGURE_ARGS += --without-libssh2 --with-libssh +ifeq ($(shell dpkg-vendor --derives-from openKylin && echo yes),yes) + CONFIGURE_ARGS += --without-libssh2 --with-libssh endif + %: dh $@ override_dh_auto_configure: mkdir -p debian/build debian/build-gnutls debian/build-nss - # pop the last patch (nss) - quilt pop - # pop the second last patch (gnutls) - quilt pop # get the source without nss and gnutls patches tar -cf - --exclude=debian/build* --exclude=.pc . \ | tar -xf - -C debian/build # push the second last patch which must be gnutls - quilt push + patch -p1 < debian/extra-patches/90_gnutls.patch # get the source with gnutls patch applied tar -cf - --exclude=debian/build* --exclude=.pc . \ | tar -xf - -C debian/build-gnutls # push the last patch which must be nss - quilt push + patch -p1 < debian/extra-patches/99_nss.patch # get the source with nss patch applied tar -cf - --exclude=debian/build* --exclude=.pc . \ | tar -xf - -C debian/build-nss