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