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 abort_on_test_timeout();
76
77 if(!running) {
78 /* This is where this code is expected to reach */
79 int numleft;
80 CURLMsg *msg = curl_multi_info_read(m, &numleft);
81 fprintf(stderr, "Expected: not running\n");
82 if(msg && !numleft)
83 res = TEST_ERR_SUCCESS; /* this is where we should be */
84 else
85 res = TEST_ERR_FAILURE; /* not correct */
86 break; /* done */
87 }
88 fprintf(stderr, "running == %d\n", running);
89
90 FD_ZERO(&rd);
91 FD_ZERO(&wr);
92 FD_ZERO(&exc);
93
94 fprintf(stderr, "curl_multi_fdset()\n");
95
96 multi_fdset(m, &rd, &wr, &exc, &maxfd);
97
98 /* At this point, maxfd is guaranteed to be greater or equal than -1. */
99
100 select_test(maxfd + 1, &rd, &wr, &exc, &interval);
101
102 abort_on_test_timeout();
103 }
104
105 test_cleanup:
106
107 /* proper cleanup sequence - type PA */
108
109 curl_multi_remove_handle(m, c);
110 curl_multi_cleanup(m);
111 curl_easy_cleanup(c);
112 curl_global_cleanup();
113
114 return res;
115 }
116