summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorMiguel Brito <5544985+miguendes@users.noreply.github.com>2021-08-29 14:10:50 (GMT)
committerGitHub <noreply@github.com>2021-08-29 14:10:50 (GMT)
commit0897253f426068ea6a6fbe0ada01689af9ef1019 (patch)
treecb83c8a5bd26e5da59d5bc606407c8c8bb657e9a /Lib/smtplib.py
parent3fc5d84046ddbd66abac5b598956ea34605a4e5d (diff)
downloadcpython-0897253f426068ea6a6fbe0ada01689af9ef1019.zip
cpython-0897253f426068ea6a6fbe0ada01689af9ef1019.tar.gz
cpython-0897253f426068ea6a6fbe0ada01689af9ef1019.tar.bz2
bpo-43124: Fix smtplib multiple CRLF injection (GH-25987)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 7e984e8..324a1c1 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -367,10 +367,15 @@ class SMTP:
def putcmd(self, cmd, args=""):
"""Send a command to the server."""
if args == "":
- str = '%s%s' % (cmd, CRLF)
+ s = cmd
else:
- str = '%s %s%s' % (cmd, args, CRLF)
- self.send(str)
+ s = f'{cmd} {args}'
+ if '\r' in s or '\n' in s:
+ s = s.replace('\n', '\\n').replace('\r', '\\r')
+ raise ValueError(
+ f'command and arguments contain prohibited newline characters: {s}'
+ )
+ self.send(f'{s}{CRLF}')
def getreply(self):
"""Get a reply from the server.