Skip to content

Commit 1b36849

Browse files
committed
Avoid crashing python when encountering a CertificateError
The code was wrong because of a rogue "whitespace" in the if, and overriding the attribute of ssl module that was already defined, could result in segfaults of python.
1 parent 70731d1 commit 1b36849

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

S3/ConnMan.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626
from .Exceptions import ParameterError
2727
from .Utils import getBucketFromHostname
2828

29-
if not 'CertificateError ' in ssl.__dict__:
29+
if not 'CertificateError' in ssl.__dict__:
3030
class CertificateError(Exception):
3131
pass
32-
ssl.CertificateError = CertificateError
32+
else:
33+
CertificateError = ssl.CertificateError
3334

3435
__all__ = [ "ConnMan" ]
3536

@@ -131,7 +132,7 @@ def match_hostname(self):
131132
return
132133
except ValueError: # empty SSL cert means underlying SSL library didn't validate it, we don't either.
133134
return
134-
except ssl.CertificateError as e:
135+
except CertificateError as e:
135136
if not self.forgive_wildcard_cert(cert, self.hostname):
136137
raise e
137138

S3/S3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from .Exceptions import *
4242
from .MultiPart import MultiPartUpload
4343
from .S3Uri import S3Uri
44-
from .ConnMan import ConnMan, CertificateError
44+
from .ConnMan import ConnMan
4545
from .Crypto import (sign_request_v2, sign_request_v4, checksum_sha256_file,
4646
checksum_sha256_buffer, s3_quote, format_param_str)
4747

0 commit comments

Comments
 (0)