summaryrefslogtreecommitdiff
path: root/Lib/email/_parseaddr.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-07-24 23:39:00 -0700
committerGitHub <noreply@github.com>2022-07-24 23:39:00 -0700
commit94eb1e9789eacf855919cddade7d7d0d26b4f08d (patch)
tree3e02c414edbc054f33004b620018850c8b83a412 /Lib/email/_parseaddr.py
parent40f41ba5f4f27a5e0949108286320c2057541643 (diff)
downloadcpython-git-94eb1e9789eacf855919cddade7d7d0d26b4f08d.tar.gz
gh-95087: Fix IndexError in parsing invalid date in the email module (GH-95201)
Co-authored-by: wouter bolsterlee <wouter@bolsterl.ee> (cherry picked from commit ea5ed0ba51c10cfdde7651a475438551964dfdfc) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/email/_parseaddr.py')
-rw-r--r--Lib/email/_parseaddr.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index ba5ad5a36d..febe411355 100644
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -95,6 +95,8 @@ def _parsedate_tz(data):
return None
data = data[:5]
[dd, mm, yy, tm, tz] = data
+ if not (dd and mm and yy):
+ return None
mm = mm.lower()
if mm not in _monthnames:
dd, mm = mm, dd.lower()
@@ -110,6 +112,8 @@ def _parsedate_tz(data):
yy, tm = tm, yy
if yy[-1] == ',':
yy = yy[:-1]
+ if not yy:
+ return None
if not yy[0].isdigit():
yy, tz = tz, yy
if tm[-1] == ',':