mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
[3.12] bpo-40944: Fix IndexError when parse emails with truncated Message-ID, address, routes, etc (GH-20790) (GH-117974)
(cherry picked from commit 1aa8bbe62f
)
Co-authored-by: Ivan Savin <acccko@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
4d34b7f201
commit
2eaf9ba9ce
3 changed files with 51 additions and 5 deletions
|
@ -1213,7 +1213,7 @@ def get_bare_quoted_string(value):
|
|||
value is the text between the quote marks, with whitespace
|
||||
preserved and quoted pairs decoded.
|
||||
"""
|
||||
if value[0] != '"':
|
||||
if not value or value[0] != '"':
|
||||
raise errors.HeaderParseError(
|
||||
"expected '\"' but found '{}'".format(value))
|
||||
bare_quoted_string = BareQuotedString()
|
||||
|
@ -1454,7 +1454,7 @@ def get_local_part(value):
|
|||
"""
|
||||
local_part = LocalPart()
|
||||
leader = None
|
||||
if value[0] in CFWS_LEADER:
|
||||
if value and value[0] in CFWS_LEADER:
|
||||
leader, value = get_cfws(value)
|
||||
if not value:
|
||||
raise errors.HeaderParseError(
|
||||
|
@ -1613,7 +1613,7 @@ def get_domain(value):
|
|||
"""
|
||||
domain = Domain()
|
||||
leader = None
|
||||
if value[0] in CFWS_LEADER:
|
||||
if value and value[0] in CFWS_LEADER:
|
||||
leader, value = get_cfws(value)
|
||||
if not value:
|
||||
raise errors.HeaderParseError(
|
||||
|
@ -1689,6 +1689,8 @@ def get_obs_route(value):
|
|||
if value[0] in CFWS_LEADER:
|
||||
token, value = get_cfws(value)
|
||||
obs_route.append(token)
|
||||
if not value:
|
||||
break
|
||||
if value[0] == '@':
|
||||
obs_route.append(RouteComponentMarker)
|
||||
token, value = get_domain(value[1:])
|
||||
|
@ -1707,7 +1709,7 @@ def get_angle_addr(value):
|
|||
|
||||
"""
|
||||
angle_addr = AngleAddr()
|
||||
if value[0] in CFWS_LEADER:
|
||||
if value and value[0] in CFWS_LEADER:
|
||||
token, value = get_cfws(value)
|
||||
angle_addr.append(token)
|
||||
if not value or value[0] != '<':
|
||||
|
@ -1717,7 +1719,7 @@ def get_angle_addr(value):
|
|||
value = value[1:]
|
||||
# Although it is not legal per RFC5322, SMTP uses '<>' in certain
|
||||
# circumstances.
|
||||
if value[0] == '>':
|
||||
if value and value[0] == '>':
|
||||
angle_addr.append(ValueTerminal('>', 'angle-addr-end'))
|
||||
angle_addr.defects.append(errors.InvalidHeaderDefect(
|
||||
"null addr-spec in angle-addr"))
|
||||
|
@ -1769,6 +1771,9 @@ def get_name_addr(value):
|
|||
name_addr = NameAddr()
|
||||
# Both the optional display name and the angle-addr can start with cfws.
|
||||
leader = None
|
||||
if not value:
|
||||
raise errors.HeaderParseError(
|
||||
"expected name-addr but found '{}'".format(value))
|
||||
if value[0] in CFWS_LEADER:
|
||||
leader, value = get_cfws(value)
|
||||
if not value:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue