|
|
1207e4 |
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
|
|
|
1207e4 |
index 690db2c..dc49d2e 100644
|
|
|
1207e4 |
--- a/Lib/email/_parseaddr.py
|
|
|
1207e4 |
+++ b/Lib/email/_parseaddr.py
|
|
|
1207e4 |
@@ -336,7 +336,12 @@ class AddrlistClass:
|
|
|
1207e4 |
aslist.append('@')
|
|
|
1207e4 |
self.pos += 1
|
|
|
1207e4 |
self.gotonext()
|
|
|
1207e4 |
- return EMPTYSTRING.join(aslist) + self.getdomain()
|
|
|
1207e4 |
+ domain = self.getdomain()
|
|
|
1207e4 |
+ if not domain:
|
|
|
1207e4 |
+ # Invalid domain, return an empty address instead of returning a
|
|
|
1207e4 |
+ # local part to denote failed parsing.
|
|
|
1207e4 |
+ return EMPTYSTRING
|
|
|
1207e4 |
+ return EMPTYSTRING.join(aslist) + domain
|
|
|
1207e4 |
|
|
|
1207e4 |
def getdomain(self):
|
|
|
1207e4 |
"""Get the complete domain name from an address."""
|
|
|
1207e4 |
@@ -351,6 +356,10 @@ class AddrlistClass:
|
|
|
1207e4 |
elif self.field[self.pos] == '.':
|
|
|
1207e4 |
self.pos += 1
|
|
|
1207e4 |
sdlist.append('.')
|
|
|
1207e4 |
+ elif self.field[self.pos] == '@':
|
|
|
1207e4 |
+ # bpo-34155: Don't parse domains with two `@` like
|
|
|
1207e4 |
+ # `a@malicious.org@important.com`.
|
|
|
1207e4 |
+ return EMPTYSTRING
|
|
|
1207e4 |
elif self.field[self.pos] in self.atomends:
|
|
|
1207e4 |
break
|
|
|
1207e4 |
else:
|
|
|
1207e4 |
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
|
|
|
1207e4 |
index b32da9d..1739033 100644
|
|
|
1207e4 |
--- a/Lib/email/test/test_email.py
|
|
|
1207e4 |
+++ b/Lib/email/test/test_email.py
|
|
|
1207e4 |
@@ -2308,6 +2308,20 @@ class TestMiscellaneous(TestEmailBase):
|
|
|
1207e4 |
self.assertEqual(Utils.parseaddr('<>'), ('', ''))
|
|
|
1207e4 |
self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '')
|
|
|
1207e4 |
|
|
|
1207e4 |
+ def test_parseaddr_multiple_domains(self):
|
|
|
1207e4 |
+ self.assertEqual(
|
|
|
1207e4 |
+ Utils.parseaddr('a@b@c'),
|
|
|
1207e4 |
+ ('', '')
|
|
|
1207e4 |
+ )
|
|
|
1207e4 |
+ self.assertEqual(
|
|
|
1207e4 |
+ Utils.parseaddr('a@b.c@c'),
|
|
|
1207e4 |
+ ('', '')
|
|
|
1207e4 |
+ )
|
|
|
1207e4 |
+ self.assertEqual(
|
|
|
1207e4 |
+ Utils.parseaddr('a@172.17.0.1@c'),
|
|
|
1207e4 |
+ ('', '')
|
|
|
1207e4 |
+ )
|
|
|
1207e4 |
+
|
|
|
1207e4 |
def test_noquote_dump(self):
|
|
|
1207e4 |
self.assertEqual(
|
|
|
1207e4 |
Utils.formataddr(('A Silly Person', 'person@dom.ain')),
|