1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24 #include "test.h"
25
26 #include "testutil.h"
27 #include "warnless.h"
28 #include "memdebug.h"
29
30 #define TEST_HANG_TIMEOUT 60 * 1000
31
32 /*
33 * Source code in here hugely as reported in bug report 651464 by
34 * Christopher R. Palmer.
35 *
36 * Use multi interface to get document over proxy with bad port number.
37 * This caused the interface to "hang" in libcurl 7.10.2.
38 */
test(char * URL)39 CURLcode test(char *URL)
40 {
41 CURL *c = NULL;
42 CURLcode res = CURLE_OK;
43 CURLM *m = NULL;
44 fd_set rd, wr, exc;
45 int running;
46
47 start_test_timing();
48
49 global_init(CURL_GLOBAL_ALL);
50
51 easy_init(c);
52
53 /* The point here is that there must not be anything running on the given
54 proxy port */
55 if(libtest_arg2)
56 easy_setopt(c, CURLOPT_PROXY, libtest_arg2);
57 easy_setopt(c, CURLOPT_URL, URL);
58 easy_setopt(c, CURLOPT_VERBOSE, 1L);
59
60 multi_init(m);
61
62 multi_add_handle(m, c);
63
64 for(;;) {
65 struct timeval interval;
66 int maxfd = -99;
67
68 interval.tv_sec = 1;
69 interval.tv_usec = 0;
70
71 fprintf(stderr, "curl_multi_perform()\n");
72
73 multi_perform(m, &running);
74
75 while(running) {
76 CURLMcode mres;
77 int num;
78 mres = curl_multi_wait(m, NULL, 0, TEST_HANG_TIMEOUT, &num);
79 if(mres != CURLM_OK) {
80 printf("curl_multi_wait() returned %d\n", mres);
81 res = TEST_ERR_MAJOR_BAD;
82 goto test_cleanup;
83 }
84
85 abort_on_test_timeout();
86 multi_perform(m, &running);
87 abort_on_test_timeout();
88 }
89
90 abort_on_test_timeout();
91
92 if(!running) {
93 /* This is where this code is expected to reach */
94 int numleft;
95 CURLMsg *msg = curl_multi_info_read(m, &numleft);
96 fprintf(stderr, "Expected: not running\n");
97 if(msg && !numleft)
98 res = TEST_ERR_SUCCESS; /* this is where we should be */
99 else
100 res = TEST_ERR_FAILURE; /* not correct */
101 break; /* done */
102 }
103 fprintf(stderr, "running == %d\n", running);
104
105 FD_ZERO(&rd);
106 FD_ZERO(&wr);
107 FD_ZERO(&exc);
108
109 fprintf(stderr, "curl_multi_fdset()\n");
110
111 multi_fdset(m, &rd, &wr, &exc, &maxfd);
112
113 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
114
115 select_test(maxfd + 1, &rd, &wr, &exc, &interval);
116
117 abort_on_test_timeout();
118 }
119
120 test_cleanup:
121
122 /* proper cleanup sequence - type PA */
123
124 curl_multi_remove_handle(m, c);
125 curl_multi_cleanup(m);
126 curl_easy_cleanup(c);
127 curl_global_cleanup();
128
129 return res;
130 }
131