This commit is contained in:
Daniel Stenberg 2026-07-30 18:18:30 +08:00 committed by GitHub
commit c6fe911056
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 55 additions and 7 deletions

View file

@ -103,11 +103,11 @@ static const struct LongShort aliases[] = {
{"crlf", ARG_BOOL, ' ', C_CRLF},
{"crlfile", ARG_FILE|ARG_TLS, ' ', C_CRLFILE},
{"curves", ARG_STRG|ARG_TLS, ' ', C_CURVES},
{"data", ARG_STRG, 'd', C_DATA},
{"data-ascii", ARG_STRG, ' ', C_DATA_ASCII},
{"data-binary", ARG_STRG, ' ', C_DATA_BINARY},
{"data-raw", ARG_STRG, ' ', C_DATA_RAW},
{"data-urlencode", ARG_STRG, ' ', C_DATA_URLENCODE},
{"data", ARG_STRG|ARG_CRLF, 'd', C_DATA},
{"data-ascii", ARG_STRG|ARG_CRLF, ' ', C_DATA_ASCII},
{"data-binary", ARG_STRG|ARG_CRLF, ' ', C_DATA_BINARY},
{"data-raw", ARG_STRG|ARG_CRLF, ' ', C_DATA_RAW},
{"data-urlencode", ARG_STRG|ARG_CRLF, ' ', C_DATA_URLENCODE},
{"delegation", ARG_STRG, ' ', C_DELEGATION},
{"digest", ARG_BOOL, ' ', C_DIGEST},
{"disable", ARG_BOOL, 'q', C_DISABLE},
@ -375,7 +375,7 @@ static const struct LongShort aliases[] = {
#ifdef USE_WATT32
{"wdebug", ARG_BOOL, ' ', C_WDEBUG},
#endif
{"write-out", ARG_STRG, 'w', C_WRITE_OUT},
{"write-out", ARG_STRG|ARG_CRLF, 'w', C_WRITE_OUT},
{"xattr", ARG_BOOL, ' ', C_XATTR},
};
@ -2930,6 +2930,16 @@ static bool has_leading_unicode(const unsigned char *arg)
return (arg[0] == 0xe2) && (arg[1] == 0x80) && (arg[2] & 0x80);
}
static bool has_crlf(const char *arg)
{
while(*arg) {
if(ISNEWLINE(*arg))
return TRUE;
arg++;
}
return FALSE;
}
/* the longest command line option, excluding the leading -- */
#define MAX_OPTION_LEN 26
@ -3065,6 +3075,11 @@ ParameterError getparameter(const char *flag, /* f or -long-flag */
break;
}
if(!(a->desc & ARG_CRLF) && has_crlf(nextarg)) {
errorf("Argument contains CR or LF");
err = PARAM_BAD_USE;
break;
}
if(has_leading_unicode((const unsigned char *)nextarg)) {
warnf("The argument '%s' starts with a Unicode character. "
"Maybe ASCII was intended?", nextarg);

View file

@ -328,6 +328,7 @@ typedef enum {
#define ARG_TYPEMASK 0x07
#define ARGTYPE(x) ((x) & ARG_TYPEMASK)
#define ARG_CRLF 0x08 /* allow CR and LF in argument */
#define ARG_DEPR 0x10 /* deprecated option */
#define ARG_CLEAR 0x20 /* clear cmdline argument */
#define ARG_TLS 0x40 /* requires TLS support */

View file

@ -242,7 +242,7 @@ test1979 test1980 test1981 test1982 test1983 test1984 \
\
test2000 test2001 test2002 test2003 test2004 test2005 test2006 test2007 \
test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \
\
test2016 \
test2023 \
test2024 test2025 test2026 test2027 test2028 test2029 test2030 test2031 \
test2032 test2033 test2034 test2035 test2036 test2037 test2038 test2039 \

32
tests/data/test2016 Normal file
View file

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="US-ASCII"?>
<testcase>
<info>
<keywords>
HTTP
</keywords>
</info>
# Server-side
<reply>
</reply>
# Client-side
<client>
<server>
http
</server>
<name>
Attempt sending a carriage return in a HTTP header
</name>
<command>
http://%HOSTIP:%HTTPPORT/%TESTNUMBER -H 'A: %CR'
</command>
</client>
# Verify data after the test has been "shot"
<verify>
<errorcode>
2
</errorcode>
</verify>
</testcase>