lib553.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. /* This test case and code is based on the bug recipe Joe Malicki provided for
  25. * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release.
  26. */
  27. #include "test.h"
  28. #include "memdebug.h"
  29. #define POSTLEN 40960
  30. static size_t myreadfunc(char *ptr, size_t size, size_t nmemb, void *stream)
  31. {
  32. static size_t total = POSTLEN;
  33. static char buf[1024];
  34. (void)stream;
  35. memset(buf, 'A', sizeof(buf));
  36. size *= nmemb;
  37. if(size > total)
  38. size = total;
  39. if(size > sizeof(buf))
  40. size = sizeof(buf);
  41. memcpy(ptr, buf, size);
  42. total -= size;
  43. return size;
  44. }
  45. #define NUM_HEADERS 8
  46. #define SIZE_HEADERS 5000
  47. static char buf[SIZE_HEADERS + 100];
  48. int test(char *URL)
  49. {
  50. CURL *curl;
  51. CURLcode res = CURLE_FAILED_INIT;
  52. int i;
  53. struct curl_slist *headerlist = NULL, *hl;
  54. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  55. fprintf(stderr, "curl_global_init() failed\n");
  56. return TEST_ERR_MAJOR_BAD;
  57. }
  58. curl = curl_easy_init();
  59. if(!curl) {
  60. fprintf(stderr, "curl_easy_init() failed\n");
  61. curl_global_cleanup();
  62. return TEST_ERR_MAJOR_BAD;
  63. }
  64. for(i = 0; i < NUM_HEADERS; i++) {
  65. int len = msnprintf(buf, sizeof(buf), "Header%d: ", i);
  66. memset(&buf[len], 'A', SIZE_HEADERS);
  67. buf[len + SIZE_HEADERS] = 0; /* null-terminate */
  68. hl = curl_slist_append(headerlist, buf);
  69. if(!hl)
  70. goto test_cleanup;
  71. headerlist = hl;
  72. }
  73. hl = curl_slist_append(headerlist, "Expect: ");
  74. if(!hl)
  75. goto test_cleanup;
  76. headerlist = hl;
  77. test_setopt(curl, CURLOPT_URL, URL);
  78. test_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
  79. test_setopt(curl, CURLOPT_POST, 1L);
  80. test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
  81. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  82. test_setopt(curl, CURLOPT_HEADER, 1L);
  83. test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
  84. res = curl_easy_perform(curl);
  85. test_cleanup:
  86. curl_easy_cleanup(curl);
  87. curl_slist_free_all(headerlist);
  88. curl_global_cleanup();
  89. return (int)res;
  90. }