You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
patch smtplib:when SMTPDataError, rset crashes with sslerror #43311
File "smtplib.pyc", line 690, in sendmail
File "smtplib.pyc", line 445, in rset
File "smtplib.pyc", line 370, in docmd
File "smtplib.pyc", line 344, in getreply
File "smtplib.pyc", line 159, in readline
sslerror: (8, 'EOF occurred in violation of protocol')
traced from a py2.3 - yet unchanged.
=> hides original error SMTPDataError. such
SMTPDataError may have forced a disconnect of server.
patch for py2.3,py2.4,..
( I have this patch in my MUST-DO-PATCHes after any
Python installation. )
--
the patch passes on any error in this rset() location.
it also patches a error in PLAIN authentication
could cleanly catch socket.sslerror / socket.error /
EnvironmentError, yet ssl not always there ...
rset() is tested otherwise, so the nacked except is ok?
(there should maybe be special a common base Exception
class "IOBaseError" for : EnvironmentError(IOError,
OSError), EOFError, socket.error, socket.sslerror,
ftplib.all_errors, etc. Nice as it and not all IO
sublibs have to be imported to catch such errors.)
---
the same problem is with smtp.quit() on many SSL'ed
connections (without any other errors occuring): a
final socket.sslerror is raised during quit().
There may be a problem in the termination code of
ssl-FakeSockets or ssl.c . Or the same type of error
catch (on IOBaseError) should be applied. I am not sure
in my apps I (must) catch on smtp.quit() generally.
(Compare also bug bpo-978833 / shutdown(2)-remedy in
httplib's SSL FakeSocket - this shutdown(2) remedy
patch of bpo-978833 I still have it on my MUST list
(py2.3/py2.4 installations), otherwise this FakeSocket
doesn't close fully in a FTPS application (where
termination on data channel is crucial for getting
response on the control channel) - and most likely puts
tremendous connection load on HTTPS servers because of
stale unterminated HTTPS connections while the bug may
not be obvious in casual usage. I'm not completely
clear about the nature of this error. Thus, what I say
is based on trial-and-error.
The change to the encode_plain method in the patch was done via bpo-1075928 on 2004-12-06. The try/except change around a call to self.rset() was never implemented.
kxroberto commented on Aug 23, 2010
kxrobertomannequin
MannequinAuthor
More actions
still I think all 3 self.rset()'s in SMTP.sendmail, which are followed by a raise <someerror> statement have to be bracketed with an except clause or so - nowadays better like """
try: self.res()
except (EnvironmentError, SMTPException):
pass
""", as all socket.error, sslerror seem meanwhile correctly inherited (via IOError).
Because the original error must pop up, not a side effect of state cleaning!
kxroberto commented on Nov 15, 2011
kxrobertomannequin
MannequinAuthor
More actions
ping!
perhaps I forgot to write that I uploaded the cleaned patch also on 2010-08-23. I really think this simple patch is necessary. Just seen the same problem again - as I forgot the patch in one of my recent Python update installations.
When SMTPDataError, SMTPRecipientsRefused, SMTPSenderRefused should be raised, very likely a subsequent error (like closed connection etc.) overlappes the original Exception during self.rset(), and one will not be able to locate the problem on user level in eons ..
This patch is still in my vital-patches collection which I have to apply after every Python update since years.
zvyn commented on Jul 23, 2014
zvynmannequin
Mannequin
More actions
This bug was resolved for SMTPServerDisconnected exceptions but not for SSLError. Is it still reproducible? If so, the attached patch should fix it for 3.x (couldn't test if it does because I don't know how to reproduce the error).
This looks resolved at main — I can't reproduce the masking. A TLS server that replies 554 to DATA and then breaks the connection (TCP RST, raw close, or clean close_notify) always surfaces SMTPDataError(554, ...) from sendmail(). Forcing a literal ssl.SSLError ([SSL: RECORD_LAYER_FAILURE]) on the rset() read gives SMTPServerDisconnected with the SSLError as __context__, which _rset() swallows.
Two changes since 2006 close it: bpo-17498 (afb151a) routes all three sendmail() error paths through _rset(), and ssl.SSLError subclasses OSError, so send()/getreply() already normalize it to SMTPServerDisconnected — the case that couldn't be tested back in 2014.
There's no regression test for the TLS variant (test__rest_from_mail_cmd is plaintext only); I can add one if that's worth having.
Activity
kxroberto commentedon May 3, 2006
File "smtplib.pyc", line 690, in sendmail
File "smtplib.pyc", line 445, in rset
File "smtplib.pyc", line 370, in docmd
File "smtplib.pyc", line 344, in getreply
File "smtplib.pyc", line 159, in readline
sslerror: (8, 'EOF occurred in violation of protocol')
traced from a py2.3 - yet unchanged.
=> hides original error SMTPDataError. such
SMTPDataError may have forced a disconnect of server.
patch for py2.3,py2.4,..
( I have this patch in my MUST-DO-PATCHes after any
Python installation. )
--
the patch passes on any error in this rset() location.
it also patches a error in PLAIN authentication
could cleanly catch socket.sslerror / socket.error /
EnvironmentError, yet ssl not always there ...
rset() is tested otherwise, so the nacked except is ok?
(there should maybe be special a common base Exception
class "IOBaseError" for : EnvironmentError(IOError,
OSError), EOFError, socket.error, socket.sslerror,
ftplib.all_errors, etc. Nice as it and not all IO
sublibs have to be imported to catch such errors.)
---
the same problem is with smtp.quit() on many SSL'ed
connections (without any other errors occuring): a
final socket.sslerror is raised during quit().
There may be a problem in the termination code of
ssl-FakeSockets or ssl.c . Or the same type of error
catch (on IOBaseError) should be applied. I am not sure
(Compare also bug bpo-978833 / shutdown(2)-remedy in
httplib's SSL FakeSocket - this shutdown(2) remedy
patch of bpo-978833 I still have it on my MUST list
(py2.3/py2.4 installations), otherwise this FakeSocket
doesn't close fully in a FTPS application (where
termination on data channel is crucial for getting
response on the control channel) - and most likely puts
tremendous connection load on HTTPS servers because of
stale unterminated HTTPS connections while the bug may
not be obvious in casual usage. I'm not completely
clear about the nature of this error. Thus, what I say
is based on trial-and-error.
-robert
hwundram commentedon May 5, 2006
Logged In: YES
user_id=791932
Where is the patch? :-)
kxroberto commentedon May 5, 2006
Logged In: YES
user_id=972995
here (i forgot the upload checkbox?)
BreamoreBoy commentedon Aug 22, 2010
The change to the encode_plain method in the patch was done via bpo-1075928 on 2004-12-06. The try/except change around a call to self.rset() was never implemented.
kxroberto commentedon Aug 23, 2010
still I think all 3 self.rset()'s in SMTP.sendmail, which are followed by a raise <someerror> statement have to be bracketed with an except clause or so - nowadays better like """
try: self.res()
except (EnvironmentError, SMTPException):
pass
""", as all socket.error, sslerror seem meanwhile correctly inherited (via IOError).
Because the original error must pop up, not a side effect of state cleaning!
kxroberto commentedon Nov 15, 2011
ping!
perhaps I forgot to write that I uploaded the cleaned patch also on 2010-08-23. I really think this simple patch is necessary. Just seen the same problem again - as I forgot the patch in one of my recent Python update installations.
When SMTPDataError, SMTPRecipientsRefused, SMTPSenderRefused should be raised, very likely a subsequent error (like closed connection etc.) overlappes the original Exception during self.rset(), and one will not be able to locate the problem on user level in eons ..
This patch is still in my vital-patches collection which I have to apply after every Python update since years.
zvyn commentedon Jul 23, 2014
This bug was resolved for SMTPServerDisconnected exceptions but not for SSLError. Is it still reproducible? If so, the attached patch should fix it for 3.x (couldn't test if it does because I don't know how to reproduce the error).
terryjreedy commentedon Aug 29, 2014
David, do you agree with either of the proposed changes?
bitdancer commentedon Aug 29, 2014
Milan's patch should be correct. It would be nice to have a reproducer.
tiran commentedon Sep 8, 2016
Is this still an issue? The bug is 10 years old and the patch two years.
soreavis commentedon Jul 19, 2026
This looks resolved at main — I can't reproduce the masking. A TLS server that replies 554 to DATA and then breaks the connection (TCP RST, raw close, or clean close_notify) always surfaces
SMTPDataError(554, ...)fromsendmail(). Forcing a literalssl.SSLError([SSL: RECORD_LAYER_FAILURE]) on therset()read givesSMTPServerDisconnectedwith theSSLErroras__context__, which_rset()swallows.Two changes since 2006 close it: bpo-17498 (afb151a) routes all three
sendmail()error paths through_rset(), andssl.SSLErrorsubclassesOSError, sosend()/getreply()already normalize it toSMTPServerDisconnected— the case that couldn't be tested back in 2014.There's no regression test for the TLS variant (
test__rest_from_mail_cmdis plaintext only); I can add one if that's worth having.Reproducer (drop a throwaway cert alongside:
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 1 -nodes -subj /CN=localhost)pythongh-43311: Add NEWS entry