| xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /*************************************************************************** | 
 | 2 |  *                                  _   _ ____  _ | 
 | 3 |  *  Project                     ___| | | |  _ \| | | 
 | 4 |  *                             / __| | | | |_) | | | 
 | 5 |  *                            | (__| |_| |  _ <| |___ | 
 | 6 |  *                             \___|\___/|_| \_\_____| | 
 | 7 |  * | 
 | 8 |  * Copyright (C) 1998 - 2022, 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 |  | 
 | 25 | /* This test case and code is based on the bug recipe Joe Malicki provided for | 
 | 26 |  * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release. | 
 | 27 |  */ | 
 | 28 |  | 
 | 29 | #include "test.h" | 
 | 30 |  | 
 | 31 | #include "memdebug.h" | 
 | 32 |  | 
 | 33 | #define POSTLEN 40960 | 
 | 34 |  | 
 | 35 | static size_t myreadfunc(char *ptr, size_t size, size_t nmemb, void *stream) | 
 | 36 | { | 
 | 37 |   static size_t total = POSTLEN; | 
 | 38 |   static char buf[1024]; | 
 | 39 |   (void)stream; | 
 | 40 |  | 
 | 41 |   memset(buf, 'A', sizeof(buf)); | 
 | 42 |  | 
 | 43 |   size *= nmemb; | 
 | 44 |   if(size > total) | 
 | 45 |     size = total; | 
 | 46 |  | 
 | 47 |   if(size > sizeof(buf)) | 
 | 48 |     size = sizeof(buf); | 
 | 49 |  | 
 | 50 |   memcpy(ptr, buf, size); | 
 | 51 |   total -= size; | 
 | 52 |   return size; | 
 | 53 | } | 
 | 54 |  | 
 | 55 | #define NUM_HEADERS 8 | 
 | 56 | #define SIZE_HEADERS 5000 | 
 | 57 |  | 
 | 58 | static char buf[SIZE_HEADERS + 100]; | 
 | 59 |  | 
 | 60 | int test(char *URL) | 
 | 61 | { | 
 | 62 |   CURL *curl; | 
 | 63 |   CURLcode res = CURLE_FAILED_INIT; | 
 | 64 |   int i; | 
 | 65 |   struct curl_slist *headerlist = NULL, *hl; | 
 | 66 |  | 
 | 67 |   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { | 
 | 68 |     fprintf(stderr, "curl_global_init() failed\n"); | 
 | 69 |     return TEST_ERR_MAJOR_BAD; | 
 | 70 |   } | 
 | 71 |  | 
 | 72 |   curl = curl_easy_init(); | 
 | 73 |   if(!curl) { | 
 | 74 |     fprintf(stderr, "curl_easy_init() failed\n"); | 
 | 75 |     curl_global_cleanup(); | 
 | 76 |     return TEST_ERR_MAJOR_BAD; | 
 | 77 |   } | 
 | 78 |  | 
 | 79 |   for(i = 0; i < NUM_HEADERS; i++) { | 
 | 80 |     int len = msnprintf(buf, sizeof(buf), "Header%d: ", i); | 
 | 81 |     memset(&buf[len], 'A', SIZE_HEADERS); | 
 | 82 |     buf[len + SIZE_HEADERS] = 0; /* null-terminate */ | 
 | 83 |     hl = curl_slist_append(headerlist,  buf); | 
 | 84 |     if(!hl) | 
 | 85 |       goto test_cleanup; | 
 | 86 |     headerlist = hl; | 
 | 87 |   } | 
 | 88 |  | 
 | 89 |   hl = curl_slist_append(headerlist, "Expect: "); | 
 | 90 |   if(!hl) | 
 | 91 |     goto test_cleanup; | 
 | 92 |   headerlist = hl; | 
 | 93 |  | 
 | 94 |   test_setopt(curl, CURLOPT_URL, URL); | 
 | 95 |   test_setopt(curl, CURLOPT_HTTPHEADER, headerlist); | 
 | 96 |   test_setopt(curl, CURLOPT_POST, 1L); | 
 | 97 |   test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN); | 
 | 98 |   test_setopt(curl, CURLOPT_VERBOSE, 1L); | 
 | 99 |   test_setopt(curl, CURLOPT_HEADER, 1L); | 
 | 100 |   test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc); | 
 | 101 |  | 
 | 102 |   res = curl_easy_perform(curl); | 
 | 103 |  | 
 | 104 | test_cleanup: | 
 | 105 |  | 
 | 106 |   curl_easy_cleanup(curl); | 
 | 107 |  | 
 | 108 |   curl_slist_free_all(headerlist); | 
 | 109 |  | 
 | 110 |   curl_global_cleanup(); | 
 | 111 |  | 
 | 112 |   return (int)res; | 
 | 113 | } |