113498266Sopenharmony_ci/***************************************************************************
213498266Sopenharmony_ci *                                  _   _ ____  _
313498266Sopenharmony_ci *  Project                     ___| | | |  _ \| |
413498266Sopenharmony_ci *                             / __| | | | |_) | |
513498266Sopenharmony_ci *                            | (__| |_| |  _ <| |___
613498266Sopenharmony_ci *                             \___|\___/|_| \_\_____|
713498266Sopenharmony_ci *
813498266Sopenharmony_ci * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
913498266Sopenharmony_ci *
1013498266Sopenharmony_ci * This software is licensed as described in the file COPYING, which
1113498266Sopenharmony_ci * you should have received as part of this distribution. The terms
1213498266Sopenharmony_ci * are also available at https://curl.se/docs/copyright.html.
1313498266Sopenharmony_ci *
1413498266Sopenharmony_ci * You may opt to use, copy, modify, merge, publish, distribute and/or sell
1513498266Sopenharmony_ci * copies of the Software, and permit persons to whom the Software is
1613498266Sopenharmony_ci * furnished to do so, under the terms of the COPYING file.
1713498266Sopenharmony_ci *
1813498266Sopenharmony_ci * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
1913498266Sopenharmony_ci * KIND, either express or implied.
2013498266Sopenharmony_ci *
2113498266Sopenharmony_ci * SPDX-License-Identifier: curl
2213498266Sopenharmony_ci *
2313498266Sopenharmony_ci ***************************************************************************/
2413498266Sopenharmony_ci#include "test.h"
2513498266Sopenharmony_ci
2613498266Sopenharmony_ci#include "testutil.h"
2713498266Sopenharmony_ci#include "warnless.h"
2813498266Sopenharmony_ci#include "memdebug.h"
2913498266Sopenharmony_ci
3013498266Sopenharmony_ci/* The maximum string length limit (CURL_MAX_INPUT_LENGTH) is an internal
3113498266Sopenharmony_ci   define not publicly exposed so we set our own */
3213498266Sopenharmony_ci#define MAX_INPUT_LENGTH 8000000
3313498266Sopenharmony_ci
3413498266Sopenharmony_cistatic char buffer[MAX_INPUT_LENGTH + 2];
3513498266Sopenharmony_ci
3613498266Sopenharmony_ciint test(char *URL)
3713498266Sopenharmony_ci{
3813498266Sopenharmony_ci  const struct curl_easyoption *o;
3913498266Sopenharmony_ci  CURL *easy;
4013498266Sopenharmony_ci  int error = 0;
4113498266Sopenharmony_ci  (void)URL;
4213498266Sopenharmony_ci
4313498266Sopenharmony_ci  curl_global_init(CURL_GLOBAL_ALL);
4413498266Sopenharmony_ci  easy = curl_easy_init();
4513498266Sopenharmony_ci  if(!easy) {
4613498266Sopenharmony_ci    curl_global_cleanup();
4713498266Sopenharmony_ci    return 1;
4813498266Sopenharmony_ci  }
4913498266Sopenharmony_ci
5013498266Sopenharmony_ci  /* make it a null-terminated C string with just As */
5113498266Sopenharmony_ci  memset(buffer, 'A', MAX_INPUT_LENGTH + 1);
5213498266Sopenharmony_ci  buffer[MAX_INPUT_LENGTH + 1] = 0;
5313498266Sopenharmony_ci
5413498266Sopenharmony_ci  printf("string length: %d\n", (int)strlen(buffer));
5513498266Sopenharmony_ci
5613498266Sopenharmony_ci  for(o = curl_easy_option_next(NULL);
5713498266Sopenharmony_ci      o;
5813498266Sopenharmony_ci      o = curl_easy_option_next(o)) {
5913498266Sopenharmony_ci    if(o->type == CURLOT_STRING) {
6013498266Sopenharmony_ci      CURLcode result;
6113498266Sopenharmony_ci      /*
6213498266Sopenharmony_ci       * Whitelist string options that are safe for abuse
6313498266Sopenharmony_ci       */
6413498266Sopenharmony_ci      CURL_IGNORE_DEPRECATION(
6513498266Sopenharmony_ci        switch(o->id) {
6613498266Sopenharmony_ci        case CURLOPT_PROXY_TLSAUTH_TYPE:
6713498266Sopenharmony_ci        case CURLOPT_TLSAUTH_TYPE:
6813498266Sopenharmony_ci        case CURLOPT_RANDOM_FILE:
6913498266Sopenharmony_ci        case CURLOPT_EGDSOCKET:
7013498266Sopenharmony_ci          continue;
7113498266Sopenharmony_ci        default:
7213498266Sopenharmony_ci          /* check this */
7313498266Sopenharmony_ci          break;
7413498266Sopenharmony_ci        }
7513498266Sopenharmony_ci      )
7613498266Sopenharmony_ci
7713498266Sopenharmony_ci      /* This is a string. Make sure that passing in a string longer
7813498266Sopenharmony_ci         CURL_MAX_INPUT_LENGTH returns an error */
7913498266Sopenharmony_ci      result = curl_easy_setopt(easy, o->id, buffer);
8013498266Sopenharmony_ci      switch(result) {
8113498266Sopenharmony_ci      case CURLE_BAD_FUNCTION_ARGUMENT: /* the most normal */
8213498266Sopenharmony_ci      case CURLE_UNKNOWN_OPTION: /* left out from the build */
8313498266Sopenharmony_ci      case CURLE_NOT_BUILT_IN: /* not supported */
8413498266Sopenharmony_ci      case CURLE_UNSUPPORTED_PROTOCOL: /* detected by protocol2num() */
8513498266Sopenharmony_ci        break;
8613498266Sopenharmony_ci      default:
8713498266Sopenharmony_ci        /* all other return codes are unexpected */
8813498266Sopenharmony_ci        fprintf(stderr, "curl_easy_setopt(%s...) returned %d\n",
8913498266Sopenharmony_ci                o->name, (int)result);
9013498266Sopenharmony_ci        error++;
9113498266Sopenharmony_ci        break;
9213498266Sopenharmony_ci      }
9313498266Sopenharmony_ci    }
9413498266Sopenharmony_ci  }
9513498266Sopenharmony_ci  curl_easy_cleanup(easy);
9613498266Sopenharmony_ci  curl_global_cleanup();
9713498266Sopenharmony_ci  return error;
9813498266Sopenharmony_ci}
99