* calling function deems it to be) then the input will be returned in
* the address part with the hostname being NULL.
*/
-static CURLcode smtp_parse_address(const char *fqma, char **address,
- struct hostname *host, const char **suffix)
+static CURLcode smtp_parse_address(struct Curl_easy *data, const char *fqma,
+ char **address, struct hostname *host,
+ const char **suffix)
{
CURLcode result = CURLE_OK;
size_t length;
char *addressend;
+ char *dup;
+
+ /* A CR or LF in the address ends up verbatim in the MAIL FROM/RCPT TO
+ command line, so a crafted address could smuggle further SMTP commands
+ onto the wire. Reject it before the command is built. */
+ if(strpbrk(fqma, "\r\n")) {
+ failf(data, "Refusing to send email address with a CR or LF");
+ return CURLE_BAD_FUNCTION_ARGUMENT;
+ }
/* Duplicate the fully qualified email address so we can manipulate it,
ensuring it does not contain the delimiters if specified */
- char *dup = curlx_strdup(fqma[0] == '<' ? fqma + 1 : fqma);
+ dup = curlx_strdup(fqma[0] == '<' ? fqma + 1 : fqma);
if(!dup)
return CURLE_OUT_OF_MEMORY;
/* Parse the mailbox to verify into the local address and hostname
parts, converting the hostname to an IDN A-label if necessary */
- result = smtp_parse_address(smtp->rcpt->data,
+ result = smtp_parse_address(data, smtp->rcpt->data,
&address, &host, &suffix);
if(result)
return result;
/* Parse the FROM mailbox into the local address and hostname parts,
converting the hostname to an IDN A-label if necessary */
- result = smtp_parse_address(data->set.str[STRING_MAIL_FROM],
+ result = smtp_parse_address(data, data->set.str[STRING_MAIL_FROM],
&address, &host, &suffix);
if(result)
goto out;
/* Parse the AUTH mailbox into the local address and hostname parts,
converting the hostname to an IDN A-label if necessary */
- result = smtp_parse_address(data->set.str[STRING_MAIL_AUTH],
+ result = smtp_parse_address(data, data->set.str[STRING_MAIL_AUTH],
&address, &host, &suffix);
if(result)
goto out;
/* Parse the recipient mailbox into the local address and hostname parts,
converting the hostname to an IDN A-label if necessary */
- result = smtp_parse_address(smtp->rcpt->data,
+ result = smtp_parse_address(data, smtp->rcpt->data,
&address, &host, &suffix);
if(result)
return result;
--- /dev/null
+<?xml version="1.0" encoding="US-ASCII"?>
+<testcase>
+<info>
+<keywords>
+SMTP
+</keywords>
+</info>
+
+# Server-side
+<reply>
+</reply>
+
+# Client-side
+<client>
+<server>
+smtp
+</server>
+<name>
+SMTP --mail-from with embedded CRLF is rejected
+</name>
+<file1 name="%LOGDIR/test%TESTNUMBER.eml" crlf="yes">
+From: different
+To: another
+
+body
+</file1>
+# read the sender from a config file so the raw CR LF reaches curl intact
+# regardless of how the platform passes command line arguments
+<file2 name="%LOGDIR/test%TESTNUMBER.config">
+mail-from = "sender@example.com\r\nDATA"
+</file2>
+<command>
+smtp://%HOSTIP:%SMTPPORT/%TESTNUMBER --mail-rcpt recipient@example.com -K %LOGDIR/test%TESTNUMBER.config -T %LOGDIR/test%TESTNUMBER.eml
+</command>
+</client>
+
+# Verify data after the test has been "shot"
+<verify>
+# 43 - CURLE_BAD_FUNCTION_ARGUMENT
+<errorcode>
+43
+</errorcode>
+# the injected DATA command must never reach the server
+<protocol crlf="yes">
+EHLO %TESTNUMBER
+QUIT
+</protocol>
+</verify>
+</testcase>