lib504.c (3391B)
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 "first.h" 25 26 #include "memdebug.h" 27 28 /* 29 * Source code in here hugely as reported in bug report 651464 by 30 * Christopher R. Palmer. 31 * 32 * Use multi interface to get document over proxy with bad port number. 33 * This caused the interface to "hang" in libcurl 7.10.2. 34 */ 35 static CURLcode test_lib504(char *URL) 36 { 37 CURL *c = NULL; 38 CURLcode res = CURLE_OK; 39 CURLM *m = NULL; 40 fd_set rd, wr, exc; 41 int running; 42 43 start_test_timing(); 44 45 global_init(CURL_GLOBAL_ALL); 46 47 easy_init(c); 48 49 /* The point here is that there must not be anything running on the given 50 proxy port */ 51 if(libtest_arg2) 52 easy_setopt(c, CURLOPT_PROXY, libtest_arg2); 53 easy_setopt(c, CURLOPT_URL, URL); 54 easy_setopt(c, CURLOPT_VERBOSE, 1L); 55 56 multi_init(m); 57 58 multi_add_handle(m, c); 59 60 for(;;) { 61 struct timeval interval; 62 int maxfd = -99; 63 64 interval.tv_sec = 1; 65 interval.tv_usec = 0; 66 67 curl_mfprintf(stderr, "curl_multi_perform()\n"); 68 69 multi_perform(m, &running); 70 71 while(running) { 72 CURLMcode mres; 73 int num; 74 mres = curl_multi_wait(m, NULL, 0, TEST_HANG_TIMEOUT, &num); 75 if(mres != CURLM_OK) { 76 curl_mprintf("curl_multi_wait() returned %d\n", mres); 77 res = TEST_ERR_MAJOR_BAD; 78 goto test_cleanup; 79 } 80 81 abort_on_test_timeout(); 82 multi_perform(m, &running); 83 abort_on_test_timeout(); 84 } 85 86 abort_on_test_timeout(); 87 88 if(!running) { 89 /* This is where this code is expected to reach */ 90 int numleft; 91 CURLMsg *msg = curl_multi_info_read(m, &numleft); 92 curl_mfprintf(stderr, "Expected: not running\n"); 93 if(msg && !numleft) 94 res = TEST_ERR_SUCCESS; /* this is where we should be */ 95 else 96 res = TEST_ERR_FAILURE; /* not correct */ 97 break; /* done */ 98 } 99 curl_mfprintf(stderr, "running == %d\n", running); 100 101 FD_ZERO(&rd); 102 FD_ZERO(&wr); 103 FD_ZERO(&exc); 104 105 curl_mfprintf(stderr, "curl_multi_fdset()\n"); 106 107 multi_fdset(m, &rd, &wr, &exc, &maxfd); 108 109 /* At this point, maxfd is guaranteed to be greater or equal than -1. */ 110 111 select_test(maxfd + 1, &rd, &wr, &exc, &interval); 112 113 abort_on_test_timeout(); 114 } 115 116 test_cleanup: 117 118 /* proper cleanup sequence - type PA */ 119 120 curl_multi_remove_handle(m, c); 121 curl_multi_cleanup(m); 122 curl_easy_cleanup(c); 123 curl_global_cleanup(); 124 125 return res; 126 }