Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c1143539
Commit
c1143539
authored
Jan 25, 2014
by
Georg Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#16042: CVE-2013-1752: smtplib fix for unlimited readline() from socket
parent
f580d5b6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
4 deletions
+43
-4
Lib/smtplib.py
Lib/smtplib.py
+4
-1
Lib/test/mock_socket.py
Lib/test/mock_socket.py
+7
-2
Lib/test/test_smtplib.py
Lib/test/test_smtplib.py
+29
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/smtplib.py
View file @
c1143539
...
@@ -62,6 +62,7 @@ SMTP_PORT = 25
...
@@ -62,6 +62,7 @@ SMTP_PORT = 25
SMTP_SSL_PORT
=
465
SMTP_SSL_PORT
=
465
CRLF
=
"
\
r
\
n
"
CRLF
=
"
\
r
\
n
"
bCRLF
=
b"
\
r
\
n
"
bCRLF
=
b"
\
r
\
n
"
_MAXLINE
=
8192
# more than 8 times larger than RFC 821, 4.5.3
OLDSTYLE_AUTH
=
re
.
compile
(
r"auth=(.*)"
,
re
.
I
)
OLDSTYLE_AUTH
=
re
.
compile
(
r"auth=(.*)"
,
re
.
I
)
...
@@ -364,7 +365,7 @@ class SMTP:
...
@@ -364,7 +365,7 @@ class SMTP:
self.file = self.sock.makefile('rb')
self.file = self.sock.makefile('rb')
while 1:
while 1:
try:
try:
line = self.file.readline()
line = self.file.readline(
_MAXLINE + 1
)
except socket.error as e:
except socket.error as e:
self.close()
self.close()
raise SMTPServerDisconnected("Connection unexpectedly closed: "
raise SMTPServerDisconnected("Connection unexpectedly closed: "
...
@@ -374,6 +375,8 @@ class SMTP:
...
@@ -374,6 +375,8 @@ class SMTP:
raise SMTPServerDisconnected("Connection unexpectedly closed")
raise SMTPServerDisconnected("Connection unexpectedly closed")
if self.debuglevel > 0:
if self.debuglevel > 0:
print('
reply
:
', repr(line), file=stderr)
print('
reply
:
', repr(line), file=stderr)
if len(line) > _MAXLINE:
raise SMTPResponseException(500, "Line too long.")
resp.append(line[4:].strip(b'
\
t
\
r
\
n
'))
resp.append(line[4:].strip(b'
\
t
\
r
\
n
'))
code = line[:3]
code = line[:3]
# Check that the error code is syntactically correct.
# Check that the error code is syntactically correct.
...
...
Lib/test/mock_socket.py
View file @
c1143539
...
@@ -21,8 +21,13 @@ class MockFile:
...
@@ -21,8 +21,13 @@ class MockFile:
"""
"""
def
__init__
(
self
,
lines
):
def
__init__
(
self
,
lines
):
self
.
lines
=
lines
self
.
lines
=
lines
def
readline
(
self
):
def
readline
(
self
,
limit
=-
1
):
return
self
.
lines
.
pop
(
0
)
+
b'
\
r
\
n
'
result
=
self
.
lines
.
pop
(
0
)
+
b'
\
r
\
n
'
if
limit
>=
0
:
# Re-insert the line, removing the \r\n we added.
self
.
lines
.
insert
(
0
,
result
[
limit
:
-
2
])
result
=
result
[:
limit
]
return
result
def
close
(
self
):
def
close
(
self
):
pass
pass
...
...
Lib/test/test_smtplib.py
View file @
c1143539
...
@@ -569,6 +569,33 @@ class BadHELOServerTests(unittest.TestCase):
...
@@ -569,6 +569,33 @@ class BadHELOServerTests(unittest.TestCase):
HOST
,
self
.
port
,
'localhost'
,
3
)
HOST
,
self
.
port
,
'localhost'
,
3
)
@
unittest
.
skipUnless
(
threading
,
'Threading required for this test.'
)
class
TooLongLineTests
(
unittest
.
TestCase
):
respdata
=
b'250 OK'
+
(
b'.'
*
smtplib
.
_MAXLINE
*
2
)
+
b'
\
n
'
def
setUp
(
self
):
self
.
old_stdout
=
sys
.
stdout
self
.
output
=
io
.
StringIO
()
sys
.
stdout
=
self
.
output
self
.
evt
=
threading
.
Event
()
self
.
sock
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
sock
.
settimeout
(
15
)
self
.
port
=
support
.
bind_port
(
self
.
sock
)
servargs
=
(
self
.
evt
,
self
.
respdata
,
self
.
sock
)
threading
.
Thread
(
target
=
server
,
args
=
servargs
).
start
()
self
.
evt
.
wait
()
self
.
evt
.
clear
()
def
tearDown
(
self
):
self
.
evt
.
wait
()
sys
.
stdout
=
self
.
old_stdout
def
testLineTooLong
(
self
):
self
.
assertRaises
(
smtplib
.
SMTPResponseException
,
smtplib
.
SMTP
,
HOST
,
self
.
port
,
'localhost'
,
3
)
sim_users
=
{
'Mr.A@somewhere.com'
:
'John A'
,
sim_users
=
{
'Mr.A@somewhere.com'
:
'John A'
,
'Ms.B@xn--fo-fka.com'
:
'Sally B'
,
'Ms.B@xn--fo-fka.com'
:
'Sally B'
,
'Mrs.C@somewhereesle.com'
:
'Ruth C'
,
'Mrs.C@somewhereesle.com'
:
'Ruth C'
,
...
@@ -885,7 +912,8 @@ class SMTPSimTests(unittest.TestCase):
...
@@ -885,7 +912,8 @@ class SMTPSimTests(unittest.TestCase):
def
test_main
(
verbose
=
None
):
def
test_main
(
verbose
=
None
):
support
.
run_unittest
(
GeneralTests
,
DebuggingServerTests
,
support
.
run_unittest
(
GeneralTests
,
DebuggingServerTests
,
NonConnectingTests
,
NonConnectingTests
,
BadHELOServerTests
,
SMTPSimTests
)
BadHELOServerTests
,
SMTPSimTests
,
TooLongLineTests
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_main
()
test_main
()
Misc/NEWS
View file @
c1143539
...
@@ -50,6 +50,9 @@ Core and Builtins
...
@@ -50,6 +50,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #16042: CVE-2013-1752: smtplib: Limit amount of data read by
limiting the call to readline(). Original patch by Christian Heimes.
- Issue #20317: ExitStack.__exit__ could create a self-referential loop if an
- Issue #20317: ExitStack.__exit__ could create a self-referential loop if an
exception raised by a cleanup operation already had its context set
exception raised by a cleanup operation already had its context set
correctly (for example, by the @contextmanager decorator). The infinite
correctly (for example, by the @contextmanager decorator). The infinite
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment