Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 391511c

Browse files
bpo-37461: Fix infinite loop in parsing of specially crafted email headers (GH-14794)
* bpo-37461: Fix infinite loop in parsing of specially crafted email headers. Some crafted email header would cause the get_parameter method to run in an infinite loop causing a DoS attack surface when parsing those headers. This patch fixes that by making sure the DQUOTE character is handled to prevent going into an infinite loop. (cherry picked from commit a4a994b) Co-authored-by: Abhilash Raj <[email protected]>
1 parent 093e9b1 commit 391511c

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Lib/email/_header_value_parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2390,6 +2390,9 @@ def get_parameter(value):
23902390
while value:
23912391
if value[0] in WSP:
23922392
token, value = get_fws(value)
2393+
elif value[0] == '"':
2394+
token = ValueTerminal('"', 'DQUOTE')
2395+
value = value[1:]
23932396
else:
23942397
token, value = get_qcontent(value)
23952398
v.append(token)

Lib/test/test_email/test__header_value_parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,13 @@ def mime_parameters_as_value(self,
26382638
# Defects are apparent missing *0*, and two 'out of sequence'.
26392639
[errors.InvalidHeaderDefect]*3),
26402640

2641+
# bpo-37461: Check that we don't go into an infinite loop.
2642+
'extra_dquote': (
2643+
'r*="\'a\'\\"',
2644+
' r="\\""',
2645+
'r*=\'a\'"',
2646+
[('r', '"')],
2647+
[errors.InvalidHeaderDefect]*2),
26412648
}
26422649

26432650
@parameterize
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an inifite loop when parsing specially crafted email headers. Patch by
2+
Abhilash Raj.

0 commit comments

Comments
 (0)