1 From f5c616930b5cf148b1b2632da4f5963ff48bdf88 Mon Sep 17 00:00:00 2001
2 From: Daniel Stenberg <daniel@haxx.se>
3 Date: Thu, 7 Nov 2024 08:52:38 +0100
4 Subject: [PATCH] duphandle: also init netrc
6 The netrc init was only done in the Curl_open, meaning that a duplicated
7 handle would not get inited properly.
9 Added test 2309 to verify. It does netrc auth with a duplicated handle.
11 Regression from 3b43a05e000aa8f65bda513f733a
13 Reported-by: tranzystorekk on github
18 tests/data/Makefile.am | 2 +-
19 tests/data/test2309 | 66 ++++++++++++++++++++++++++++++++++++++
20 tests/libtest/Makefile.inc | 5 ++-
21 tests/libtest/lib2309.c | 66 ++++++++++++++++++++++++++++++++++++++
22 5 files changed, 138 insertions(+), 2 deletions(-)
23 create mode 100644 tests/data/test2309
24 create mode 100644 tests/libtest/lib2309.c
26 diff --git a/lib/easy.c b/lib/easy.c
27 index d16fa8c07afec00ab6186880eff05c925da00380..ac8fab34220d9b4f1f8f9cb7bc504a5024a46cca 100644
30 @@ -940,6 +940,7 @@ CURL *curl_easy_duphandle(CURL *d)
33 Curl_dyn_init(&outcurl->state.headerb, CURL_MAX_HTTP_HEADER);
34 + Curl_netrc_init(&outcurl->state.netrc);
36 /* the connection pool is setup on demand */
37 outcurl->state.lastconnect_id = -1;
38 diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
39 index 02bf2ae25bfd49dce27d4cd2320a2794ba5b4212..ea5221c00fd4193e1713b1313da338f1ea6aee4f 100644
40 --- a/tests/data/Makefile.am
41 +++ b/tests/data/Makefile.am
42 @@ -255,7 +255,7 @@ test2100 \
43 test2200 test2201 test2202 test2203 test2204 test2205 \
45 test2300 test2301 test2302 test2303 test2304 test2305 test2306 test2307 \
49 test2400 test2401 test2402 test2403 test2404 test2405 test2406 \
51 diff --git a/tests/data/test2309 b/tests/data/test2309
53 index 0000000000000000000000000000000000000000..4ba78ee91e179c932f8bfa776d32f311512ef8e6
55 +++ b/tests/data/test2309
67 +<data crlf="yes" nocheck="yes">
69 +Date: Tue, 09 Nov 2010 14:49:00 GMT
70 +Server: test-server/fake
71 +Last-Modified: Tue, 13 Jun 2000 12:10:00 GMT
72 +ETag: "21025-dc7-39462498"
76 +Content-Type: text/html
93 +# Reproducing issue 15496
95 +HTTP with .netrc using duped easy handle
101 +http://github.com %LOGDIR/netrc%TESTNUMBER http://%HOSTIP:%HTTPPORT/
103 +<file name="%LOGDIR/netrc%TESTNUMBER" >
108 +password $y$j9T$WUVjiVvDbRAWafDLs6cab1$01NX.oaZKf5lw8MR2Nk9Yaxv4CqbE0IaDF.GpGxPul1
114 +GET http://github.com/ HTTP/1.1
116 +Authorization: Basic %b64[daniel:$y$j9T$WUVjiVvDbRAWafDLs6cab1$01NX.oaZKf5lw8MR2Nk9Yaxv4CqbE0IaDF.GpGxPul1]b64%
118 +Proxy-Connection: Keep-Alive
123 diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
124 index 339a00fc4ed41e1491ea945ff9ebeb7caf058c69..8f58fd64229d5cbcebdb4949111b3c3184d82eb3 100644
125 --- a/tests/libtest/Makefile.inc
126 +++ b/tests/libtest/Makefile.inc
127 @@ -77,7 +77,7 @@ LIBTESTPROGS = libauthretry libntlmconnect libprereq \
128 lib1945 lib1946 lib1947 lib1948 lib1955 lib1956 lib1957 lib1958 lib1959 \
130 lib1970 lib1971 lib1972 lib1973 lib1974 lib1975 \
131 - lib2301 lib2302 lib2304 lib2305 lib2306 lib2308 \
132 + lib2301 lib2302 lib2304 lib2305 lib2306 lib2308 lib2309 \
133 lib2402 lib2404 lib2405 \
135 lib3010 lib3025 lib3026 lib3027 \
136 @@ -683,6 +683,9 @@ lib2306_LDADD = $(TESTUTIL_LIBS)
137 lib2308_SOURCES = lib2308.c $(SUPPORTFILES)
138 lib2308_LDADD = $(TESTUTIL_LIBS)
140 +lib2309_SOURCES = lib2309.c $(SUPPORTFILES)
141 +lib2309_LDADD = $(TESTUTIL_LIBS)
143 lib2402_SOURCES = lib2402.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
144 lib2402_LDADD = $(TESTUTIL_LIBS)
146 diff --git a/tests/libtest/lib2309.c b/tests/libtest/lib2309.c
148 index 0000000000000000000000000000000000000000..11f1c1fbd886846d5901b03ba9cd0314672fec99
150 +++ b/tests/libtest/lib2309.c
152 +/***************************************************************************
154 + * Project ___| | | | _ \| |
155 + * / __| | | | |_) | |
156 + * | (__| |_| | _ <| |___
157 + * \___|\___/|_| \_\_____|
159 + * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
161 + * This software is licensed as described in the file COPYING, which
162 + * you should have received as part of this distribution. The terms
163 + * are also available at https://curl.se/docs/copyright.html.
165 + * You may opt to use, copy, modify, merge, publish, distribute and/or sell
166 + * copies of the Software, and permit persons to whom the Software is
167 + * furnished to do so, under the terms of the COPYING file.
169 + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
170 + * KIND, either express or implied.
172 + * SPDX-License-Identifier: curl
174 + ***************************************************************************/
177 +#include "testtrace.h"
179 +#include <curl/curl.h>
181 +static size_t cb_ignore(char *buffer, size_t size, size_t nmemb, void *userp)
187 + return CURL_WRITEFUNC_ERROR;
190 +CURLcode test(char *URL)
194 + CURLcode res = CURLE_OK;
196 + global_init(CURL_GLOBAL_ALL);
197 + curl = curl_easy_init();
199 + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb_ignore);
200 + curl_easy_setopt(curl, CURLOPT_URL, URL);
201 + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
202 + curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg3);
203 + curl_easy_setopt(curl, CURLOPT_NETRC, (long)CURL_NETRC_REQUIRED);
204 + curl_easy_setopt(curl, CURLOPT_NETRC_FILE, libtest_arg2);
206 + curldupe = curl_easy_duphandle(curl);
208 + res = curl_easy_perform(curldupe);
209 + printf("Returned %d, should be %d.\n", res, CURLE_WRITE_ERROR);
211 + curl_easy_cleanup(curldupe);
213 + curl_easy_cleanup(curl);
215 + curl_global_cleanup();