]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
smtp: fix processing of initial dot in data
authorPatrick Monnerat <patrick@monnerat.net>
Mon, 12 Feb 2018 15:43:15 +0000 (16:43 +0100)
committerPatrick Monnerat <patrick@monnerat.net>
Mon, 12 Feb 2018 15:43:15 +0000 (16:43 +0100)
RFC 5321 4.1.1.4 specifies the CRLF terminating the DATA command
should be taken into account when chasing the <CRLF>.<CRLF> end marker.
Thus a leading dot character in data is also subject to escaping.

Tests 911 and test server are adapted to this situation.
New tests 951 and 952 check proper handling of initial dot in data.

Closes #2304

lib/smtp.c
tests/data/Makefile.inc
tests/data/test911
tests/data/test951 [new file with mode: 0644]
tests/data/test952 [new file with mode: 0644]
tests/ftpserver.pl

index d9f1a854aa9a509f23c79427f459e7733a7aa44f..3f3b45a9546eaee33e177a5e41b620c395320944 100644 (file)
@@ -1289,6 +1289,11 @@ static CURLcode smtp_perform(struct connectdata *conn, bool *connected,
   /* Store the first recipient (or NULL if not specified) */
   smtp->rcpt = data->set.mail_rcpt;
 
+  /* Initial data character is the first character in line: it is implicitly
+     preceded by a virtual CRLF. */
+  smtp->trailing_crlf = TRUE;
+  smtp->eob = 2;
+
   /* Start the first command in the DO phase */
   if((data->set.upload || data->set.mimepost.kind) && data->set.mail_rcpt)
     /* MAIL transfer */
index 9635d12a1f9649c29a92aa6d37e625727d10422c..31d29994280e875916d5eba85b7bdb43f052d72f 100644 (file)
@@ -103,7 +103,7 @@ test909 test910 test911 test912 test913 test914 test915 test916 test917 \
 test918 test919 test920 test921 test922 test923 test924 test925 test926 \
 test927 test928 test929 test930 test931 test932 test933 test934 test935 \
 test936 test937 test938 test939 test940 test941 test942 test943 test944 \
-test945 test946 test947 test948 test949 test950 \
+test945 test946 test947 test948 test949 test950 test951 test952 \
 \
 test1000 test1001 test1002 test1003 test1004 test1005 test1006 test1007 \
 test1008 test1009 test1010 test1011 test1012 test1013 test1014 test1015 \
index cc87349b8961b2395af6b4e9c9141ed0052adbc4..f4c545830fd5b26202c483ffa337c061096e52e9 100644 (file)
@@ -40,7 +40,6 @@ DATA
 QUIT\r
 </protocol>
 <upload>
-\r
 .\r
 </upload>
 </verify>
diff --git a/tests/data/test951 b/tests/data/test951
new file mode 100644 (file)
index 0000000..7d2e17b
--- /dev/null
@@ -0,0 +1,45 @@
+<testcase>
+<info>
+<keywords>
+SMTP
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+smtp
+</server>
+ <name>
+SMTP data with dot as first character
+ </name>
+<stdin>
+.This first line starts with a dot\r
+</stdin>
+<command>
+smtp://%HOSTIP:%SMTPPORT/951 --mail-rcpt recipient@example.com --mail-from sender@example.com -T -
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+EHLO 951\r
+MAIL FROM:<sender@example.com>\r
+RCPT TO:<recipient@example.com>\r
+DATA\r
+QUIT\r
+</protocol>
+<upload>
+..This first line starts with a dot\r
+.\r
+</upload>
+</verify>
+</testcase>
diff --git a/tests/data/test952 b/tests/data/test952
new file mode 100644 (file)
index 0000000..54334b2
--- /dev/null
@@ -0,0 +1,45 @@
+<testcase>
+<info>
+<keywords>
+SMTP
+</keywords>
+</info>
+
+#
+# Server-side
+<reply>
+</reply>
+
+#
+# Client-side
+<client>
+<server>
+smtp
+</server>
+ <name>
+SMTP data with single dot-only line
+ </name>
+<stdin>
+.\r
+</stdin>
+<command>
+smtp://%HOSTIP:%SMTPPORT/952 --mail-rcpt recipient@example.com --mail-from sender@example.com -T -
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+EHLO 952\r
+MAIL FROM:<sender@example.com>\r
+RCPT TO:<recipient@example.com>\r
+DATA\r
+QUIT\r
+</protocol>
+<upload>
+..\r
+.\r
+</upload>
+</verify>
+</testcase>
index 956275881deb00313bd43d5d6c5b2c3238b5f222..f7f4fa2ae389a7f2b12b23f5e149a46b87f891e7 100755 (executable)
@@ -6,7 +6,7 @@
 #                            | (__| |_| |  _ <| |___
 #                             \___|\___/|_| \_\_____|
 #
-# Copyright (C) 1998 - 2014, 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
 #
 # This software is licensed as described in the file COPYING, which
 # you should have received as part of this distribution. The terms
@@ -920,7 +920,7 @@ sub DATA_smtp {
                 print FILE $line if(!$nosave);
 
                 $raw .= $line;
-                if($raw =~ /\x0d\x0a\x2e\x0d\x0a/) {
+                if($raw =~ /(?:^|\x0d\x0a)\x2e\x0d\x0a/) {
                     # end of data marker!
                     $eob = 1;
                 }