Unverified Commit 5fc28510 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

CURL_MAX_INPUT_LENGTH: largest acceptable string input size

This limits all accepted input strings passed to libcurl to be less than
CURL_MAX_INPUT_LENGTH (8000000) bytes, for these API calls:
curl_easy_setopt() and curl_url_set().

The 8000000 number is arbitrary picked and is meant to detect mistakes
or abuse, not to limit actual practical use cases. By limiting the
acceptable string lengths we also reduce the risk of integer overflows
all over.

NOTE: This does not apply to `CURLOPT_POSTFIELDS`.

Test 1559 verifies.

Closes #3805
parent 2fe2da9f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -61,6 +61,13 @@ CURLcode Curl_setstropt(char **charp, const char *s)
  if(s) {
    char *str = strdup(s);

    if(str) {
      size_t len = strlen(str);
      if(len > CURL_MAX_INPUT_LENGTH) {
        free(str);
        return CURLE_BAD_FUNCTION_ARGUMENT;
      }
    }
    if(!str)
      return CURLE_OUT_OF_MEMORY;

+8 −0
Original line number Diff line number Diff line
@@ -642,6 +642,10 @@ static CURLUcode seturl(const char *url, CURLU *u, unsigned int flags)
   ************************************************************/
  /* allocate scratch area */
  urllen = strlen(url);
  if(urllen > CURL_MAX_INPUT_LENGTH)
    /* excessive input length */
    return CURLUE_MALFORMED_INPUT;

  path = u->scratch = malloc(urllen * 2 + 2);
  if(!path)
    return CURLUE_OUT_OF_MEMORY;
@@ -1279,6 +1283,10 @@ CURLUcode curl_url_set(CURLU *u, CURLUPart what,
    const char *newp = part;
    size_t nalloc = strlen(part);

    if(nalloc > CURL_MAX_INPUT_LENGTH)
      /* excessive input length */
      return CURLUE_MALFORMED_INPUT;

    if(urlencode) {
      const unsigned char *i;
      char *o;
+4 −0
Original line number Diff line number Diff line
@@ -79,6 +79,10 @@
*/
#define RESP_TIMEOUT (120*1000)

/* Max string intput length is a precaution against abuse and to detect junk
   input easier and better. */
#define CURL_MAX_INPUT_LENGTH 8000000

#include "cookie.h"
#include "psl.h"
#include "formdata.h"
+1 −1
Original line number Diff line number Diff line
@@ -176,7 +176,7 @@ test1525 test1526 test1527 test1528 test1529 test1530 test1531 test1532 \
test1533 test1534 test1535 test1536 test1537 test1538 \
test1540 test1541 \
test1550 test1551 test1552 test1553 test1554 test1555 test1556 test1557 \
test1558          test1560 test1561 test1562 \
test1558 test1559 test1560 test1561 test1562 \
\
test1590 test1591 test1592 \
\

tests/data/test1559

0 → 100644
+44 −0
Original line number Diff line number Diff line
<testcase>
<info>
<keywords>
CURLOPT_URL
</keywords>
</info>

<reply>
</reply>

<client>
<server>
none
</server>

# require HTTP so that CURLOPT_POSTFIELDS works as assumed
<features>
http
</features>
<tool>
lib1559
</tool>

<name>
Set excessive URL lengths
</name>
</client>

#
# Verify that the test runs to completion without crashing
<verify>
<errorcode>
0
</errorcode>
<stdout>
CURLOPT_URL 10000000 bytes URL == 43
CURLOPT_POSTFIELDS 10000000 bytes data == 0
CURLUPART_URL 10000000 bytes URL == 3
CURLUPART_SCHEME 10000000 bytes scheme == 3
CURLUPART_USER 10000000 bytes user == 3
</stdout>
</verify>

</testcase>
Loading