lib1911.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2021, 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. ***************************************************************************/
  22. #include "test.h"
  23. #include "testutil.h"
  24. #include "warnless.h"
  25. #include "memdebug.h"
  26. /* The maximum string length limit (CURL_MAX_INPUT_LENGTH) is an internal
  27. define not publicly exposed so we set our own */
  28. #define MAX_INPUT_LENGTH 8000000
  29. static char buffer[MAX_INPUT_LENGTH + 2];
  30. int test(char *URL)
  31. {
  32. const struct curl_easyoption *o;
  33. CURL *easy;
  34. int error = 0;
  35. (void)URL;
  36. curl_global_init(CURL_GLOBAL_ALL);
  37. easy = curl_easy_init();
  38. if(!easy) {
  39. curl_global_cleanup();
  40. return 1;
  41. }
  42. /* make it a zero terminated C string with just As */
  43. memset(buffer, 'A', MAX_INPUT_LENGTH + 1);
  44. buffer[MAX_INPUT_LENGTH + 1] = 0;
  45. printf("string length: %d\n", (int)strlen(buffer));
  46. for(o = curl_easy_option_next(NULL);
  47. o;
  48. o = curl_easy_option_next(o)) {
  49. if(o->type == CURLOT_STRING) {
  50. CURLcode result;
  51. /*
  52. * Whitelist string options that are safe for abuse
  53. */
  54. switch(o->id) {
  55. case CURLOPT_PROXY_TLSAUTH_TYPE:
  56. case CURLOPT_TLSAUTH_TYPE:
  57. continue;
  58. default:
  59. /* check this */
  60. break;
  61. }
  62. /* This is a string. Make sure that passing in a string longer
  63. CURL_MAX_INPUT_LENGTH returns an error */
  64. result = curl_easy_setopt(easy, o->id, buffer);
  65. switch(result) {
  66. case CURLE_BAD_FUNCTION_ARGUMENT: /* the most normal */
  67. case CURLE_UNKNOWN_OPTION: /* left out from the build */
  68. case CURLE_NOT_BUILT_IN: /* not supported */
  69. break;
  70. default:
  71. /* all other return codes are unexpected */
  72. fprintf(stderr, "curl_easy_setopt(%s...) returned %d\n",
  73. o->name, (int)result);
  74. error++;
  75. break;
  76. }
  77. }
  78. }
  79. curl_easy_cleanup(easy);
  80. curl_global_cleanup();
  81. return error;
  82. }