|
| 1 | +/*************************************************************************** |
| 2 | + * _ _ ____ _ |
| 3 | + * Project ___| | | | _ \| | |
| 4 | + * / __| | | | |_) | | |
| 5 | + * | (__| |_| | _ <| |___ |
| 6 | + * \___|\___/|_| \_\_____| |
| 7 | + * |
| 8 | + * Copyright (C) Linus Nielsen Feltzing <linus@haxx.se> |
| 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 "testtrace.h" |
| 27 | + |
| 28 | +static size_t sink2504(char *ptr, size_t size, size_t nmemb, void *ud) |
| 29 | +{ |
| 30 | + (void)ptr; |
| 31 | + (void)ud; |
| 32 | + return size * nmemb; |
| 33 | +} |
| 34 | + |
| 35 | +static void dump_cookies2504(CURL *h, const char *tag) |
| 36 | +{ |
| 37 | + struct curl_slist *cookies = NULL; |
| 38 | + struct curl_slist *nc; |
| 39 | + CURLcode rc = curl_easy_getinfo(h, CURLINFO_COOKIELIST, &cookies); |
| 40 | + |
| 41 | + curl_mprintf("== %s ==\n", tag); |
| 42 | + if(rc) { |
| 43 | + curl_mprintf("getinfo error: %d\n", (int)rc); |
| 44 | + return; |
| 45 | + } |
| 46 | + for(nc = cookies; nc; nc = nc->next) |
| 47 | + puts(nc->data); |
| 48 | + curl_slist_free_all(cookies); |
| 49 | +} |
| 50 | + |
| 51 | +static CURLcode test_lib2504(const char *URL) |
| 52 | +{ |
| 53 | + CURL *curl; |
| 54 | + CURLcode result = CURLE_OUT_OF_MEMORY; |
| 55 | + struct curl_slist *hdrs = NULL; |
| 56 | + |
| 57 | + if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { |
| 58 | + curl_mfprintf(stderr, "curl_global_init() failed\n"); |
| 59 | + return TEST_ERR_MAJOR_BAD; |
| 60 | + } |
| 61 | + |
| 62 | + curl = curl_easy_init(); |
| 63 | + if(!curl) { |
| 64 | + curl_mfprintf(stderr, "curl_easy_init() failed\n"); |
| 65 | + curl_global_cleanup(); |
| 66 | + return TEST_ERR_MAJOR_BAD; |
| 67 | + } |
| 68 | + |
| 69 | + hdrs = curl_slist_append(hdrs, "Host: victim.internal"); |
| 70 | + if(hdrs) { |
| 71 | + test_setopt(curl, CURLOPT_WRITEFUNCTION, sink2504); |
| 72 | + test_setopt(curl, CURLOPT_COOKIEFILE, ""); |
| 73 | + test_setopt(curl, CURLOPT_HTTPHEADER, hdrs); |
| 74 | + test_setopt(curl, CURLOPT_URL, URL); |
| 75 | + |
| 76 | + result = curl_easy_perform(curl); |
| 77 | + curl_mprintf("req1=%d\n", (int)result); |
| 78 | + dump_cookies2504(curl, "after request 1"); |
| 79 | + |
| 80 | + test_setopt(curl, CURLOPT_HTTPHEADER, NULL); |
| 81 | + test_setopt(curl, CURLOPT_URL, URL); |
| 82 | + |
| 83 | + result = curl_easy_perform(curl); |
| 84 | + curl_mprintf("req2=%d\n", (int)result); |
| 85 | + dump_cookies2504(curl, "after request 2"); |
| 86 | + } |
| 87 | +test_cleanup: |
| 88 | + curl_slist_free_all(hdrs); |
| 89 | + curl_easy_cleanup(curl); |
| 90 | + curl_global_cleanup(); |
| 91 | + |
| 92 | + return result; |
| 93 | +} |
0 commit comments