lib1911.c (3011B)
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 /* The maximum string length limit (CURL_MAX_INPUT_LENGTH) is an internal 29 define not publicly exposed so we set our own */ 30 #define MAX_INPUT_LENGTH 8000000 31 32 static CURLcode test_lib1911(char *URL) 33 { 34 static char testbuf[MAX_INPUT_LENGTH + 2]; 35 36 const struct curl_easyoption *o; 37 CURL *easy; 38 int error = 0; 39 (void)URL; 40 41 curl_global_init(CURL_GLOBAL_ALL); 42 easy = curl_easy_init(); 43 if(!easy) { 44 curl_global_cleanup(); 45 return TEST_ERR_EASY_INIT; 46 } 47 48 /* make it a null-terminated C string with just As */ 49 memset(testbuf, 'A', MAX_INPUT_LENGTH + 1); 50 testbuf[MAX_INPUT_LENGTH + 1] = 0; 51 52 curl_mprintf("string length: %d\n", (int)strlen(testbuf)); 53 54 for(o = curl_easy_option_next(NULL); 55 o; 56 o = curl_easy_option_next(o)) { 57 if(o->type == CURLOT_STRING) { 58 CURLcode result; 59 /* 60 * Whitelist string options that are safe for abuse 61 */ 62 switch(o->id) { 63 case CURLOPT_PROXY_TLSAUTH_TYPE: 64 case CURLOPT_TLSAUTH_TYPE: 65 case CURLOPT_RANDOM_FILE: 66 case CURLOPT_EGDSOCKET: 67 continue; 68 default: 69 /* check this */ 70 break; 71 } 72 73 /* This is a string. Make sure that passing in a string longer 74 CURL_MAX_INPUT_LENGTH returns an error */ 75 result = curl_easy_setopt(easy, o->id, testbuf); 76 switch(result) { 77 case CURLE_BAD_FUNCTION_ARGUMENT: /* the most normal */ 78 case CURLE_UNKNOWN_OPTION: /* left out from the build */ 79 case CURLE_NOT_BUILT_IN: /* not supported */ 80 case CURLE_UNSUPPORTED_PROTOCOL: /* detected by protocol2num() */ 81 break; 82 default: 83 /* all other return codes are unexpected */ 84 curl_mfprintf(stderr, "curl_easy_setopt(%s...) returned %d\n", 85 o->name, result); 86 error++; 87 break; 88 } 89 } 90 } 91 curl_easy_cleanup(easy); 92 curl_global_cleanup(); 93 return error == 0 ? CURLE_OK : TEST_ERR_FAILURE; 94 }