Compare commits

...

9 Commits
master ... f19

Author SHA1 Message Date
Slavek Kabrda 3d0d477966 Fix CVE-2013-7338 and CVE-2014-2667.
Resolves: rhbz#1078015
Resolves: rhbz#1083594

Conflicts:
	python3.spec
2014-12-04 13:42:56 +01:00
Slavek Kabrda 899a2cefac Fix CVE-2014-4650 - CGIHTTPServer URL handling
Resolves: rhbz#1113529

Conflicts:
	python3.spec
2014-11-03 16:22:55 +01:00
Matej Stuchlik 0d23a9e8e7 Fix JSON reading arbitrary process memory (rhbz#1112293) 2014-06-30 14:38:07 +02:00
Matej Stuchlik 92d5ecc93b Change behavior of ssl.match_hostname() to follow RFC 6125 (rhbz#1023742) 2013-11-08 14:30:56 +01:00
Bohuslav Kabrda 665c2a9d43 Bytecompile all *.py files properly during build (rhbz#1023607) 2013-10-30 13:28:58 +01:00
Matej Stuchlik 21653f0c2b Added fix for CVE-2013-4238 (rhbz#996399) 2013-08-23 20:05:43 +02:00
Dennis Gilmore 0807ef1b0c fix up indentation in arm patch 2013-08-04 23:18:42 +01:00
Dennis Gilmore b90901e83e fix up indentation 2013-08-04 23:18:34 +01:00
Dennis Gilmore acd32af658 disable a test that fails on arm
- enable valgrind support on arm arches
2013-08-04 23:16:29 +01:00
10 changed files with 825 additions and 5 deletions

View File

@ -0,0 +1,241 @@
diff -r e0f86c3b3685 Lib/test/nullbytecert.pem
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Lib/test/nullbytecert.pem Sun Aug 11 18:17:23 2013 +0200
@@ -0,0 +1,90 @@
+Certificate:
+ Data:
+ Version: 3 (0x2)
+ Serial Number: 0 (0x0)
+ Signature Algorithm: sha1WithRSAEncryption
+ Issuer: C=US, ST=Oregon, L=Beaverton, O=Python Software Foundation, OU=Python Core Development, CN=null.python.org\x00example.org/emailAddress=python-dev@python.org
+ Validity
+ Not Before: Aug 7 13:11:52 2013 GMT
+ Not After : Aug 7 13:12:52 2013 GMT
+ Subject: C=US, ST=Oregon, L=Beaverton, O=Python Software Foundation, OU=Python Core Development, CN=null.python.org\x00example.org/emailAddress=python-dev@python.org
+ Subject Public Key Info:
+ Public Key Algorithm: rsaEncryption
+ Public-Key: (2048 bit)
+ Modulus:
+ 00:b5:ea:ed:c9:fb:46:7d:6f:3b:76:80:dd:3a:f3:
+ 03:94:0b:a7:a6:db:ec:1d:df:ff:23:74:08:9d:97:
+ 16:3f:a3:a4:7b:3e:1b:0e:96:59:25:03:a7:26:e2:
+ 88:a9:cf:79:cd:f7:04:56:b0:ab:79:32:6e:59:c1:
+ 32:30:54:eb:58:a8:cb:91:f0:42:a5:64:27:cb:d4:
+ 56:31:88:52:ad:cf:bd:7f:f0:06:64:1f:cc:27:b8:
+ a3:8b:8c:f3:d8:29:1f:25:0b:f5:46:06:1b:ca:02:
+ 45:ad:7b:76:0a:9c:bf:bb:b9:ae:0d:16:ab:60:75:
+ ae:06:3e:9c:7c:31:dc:92:2f:29:1a:e0:4b:0c:91:
+ 90:6c:e9:37:c5:90:d7:2a:d7:97:15:a3:80:8f:5d:
+ 7b:49:8f:54:30:d4:97:2c:1c:5b:37:b5:ab:69:30:
+ 68:43:d3:33:78:4b:02:60:f5:3c:44:80:a1:8f:e7:
+ f0:0f:d1:5e:87:9e:46:cf:62:fc:f9:bf:0c:65:12:
+ f1:93:c8:35:79:3f:c8:ec:ec:47:f5:ef:be:44:d5:
+ ae:82:1e:2d:9a:9f:98:5a:67:65:e1:74:70:7c:cb:
+ d3:c2:ce:0e:45:49:27:dc:e3:2d:d4:fb:48:0e:2f:
+ 9e:77:b8:14:46:c0:c4:36:ca:02:ae:6a:91:8c:da:
+ 2f:85
+ Exponent: 65537 (0x10001)
+ X509v3 extensions:
+ X509v3 Basic Constraints: critical
+ CA:FALSE
+ X509v3 Subject Key Identifier:
+ 88:5A:55:C0:52:FF:61:CD:52:A3:35:0F:EA:5A:9C:24:38:22:F7:5C
+ X509v3 Key Usage:
+ Digital Signature, Non Repudiation, Key Encipherment
+ X509v3 Subject Alternative Name:
+ *************************************************************
+ WARNING: The values for DNS, email and URI are WRONG. OpenSSL
+ doesn't print the text after a NULL byte.
+ *************************************************************
+ DNS:altnull.python.org, email:null@python.org, URI:http://null.python.org, IP Address:192.0.2.1, IP Address:2001:DB8:0:0:0:0:0:1
+ Signature Algorithm: sha1WithRSAEncryption
+ ac:4f:45:ef:7d:49:a8:21:70:8e:88:59:3e:d4:36:42:70:f5:
+ a3:bd:8b:d7:a8:d0:58:f6:31:4a:b1:a4:a6:dd:6f:d9:e8:44:
+ 3c:b6:0a:71:d6:7f:b1:08:61:9d:60:ce:75:cf:77:0c:d2:37:
+ 86:02:8d:5e:5d:f9:0f:71:b4:16:a8:c1:3d:23:1c:f1:11:b3:
+ 56:6e:ca:d0:8d:34:94:e6:87:2a:99:f2:ae:ae:cc:c2:e8:86:
+ de:08:a8:7f:c5:05:fa:6f:81:a7:82:e6:d0:53:9d:34:f4:ac:
+ 3e:40:fe:89:57:7a:29:a4:91:7e:0b:c6:51:31:e5:10:2f:a4:
+ 60:76:cd:95:51:1a:be:8b:a1:b0:fd:ad:52:bd:d7:1b:87:60:
+ d2:31:c7:17:c4:18:4f:2d:08:25:a3:a7:4f:b7:92:ca:e2:f5:
+ 25:f1:54:75:81:9d:b3:3d:61:a2:f7:da:ed:e1:c6:6f:2c:60:
+ 1f:d8:6f:c5:92:05:ab:c9:09:62:49:a9:14:ad:55:11:cc:d6:
+ 4a:19:94:99:97:37:1d:81:5f:8b:cf:a3:a8:96:44:51:08:3d:
+ 0b:05:65:12:eb:b6:70:80:88:48:72:4f:c6:c2:da:cf:cd:8e:
+ 5b:ba:97:2f:60:b4:96:56:49:5e:3a:43:76:63:04:be:2a:f6:
+ c1:ca:a9:94
+-----BEGIN CERTIFICATE-----
+MIIE2DCCA8CgAwIBAgIBADANBgkqhkiG9w0BAQUFADCBxTELMAkGA1UEBhMCVVMx
+DzANBgNVBAgMBk9yZWdvbjESMBAGA1UEBwwJQmVhdmVydG9uMSMwIQYDVQQKDBpQ
+eXRob24gU29mdHdhcmUgRm91bmRhdGlvbjEgMB4GA1UECwwXUHl0aG9uIENvcmUg
+RGV2ZWxvcG1lbnQxJDAiBgNVBAMMG251bGwucHl0aG9uLm9yZwBleGFtcGxlLm9y
+ZzEkMCIGCSqGSIb3DQEJARYVcHl0aG9uLWRldkBweXRob24ub3JnMB4XDTEzMDgw
+NzEzMTE1MloXDTEzMDgwNzEzMTI1MlowgcUxCzAJBgNVBAYTAlVTMQ8wDQYDVQQI
+DAZPcmVnb24xEjAQBgNVBAcMCUJlYXZlcnRvbjEjMCEGA1UECgwaUHl0aG9uIFNv
+ZnR3YXJlIEZvdW5kYXRpb24xIDAeBgNVBAsMF1B5dGhvbiBDb3JlIERldmVsb3Bt
+ZW50MSQwIgYDVQQDDBtudWxsLnB5dGhvbi5vcmcAZXhhbXBsZS5vcmcxJDAiBgkq
+hkiG9w0BCQEWFXB5dGhvbi1kZXZAcHl0aG9uLm9yZzCCASIwDQYJKoZIhvcNAQEB
+BQADggEPADCCAQoCggEBALXq7cn7Rn1vO3aA3TrzA5QLp6bb7B3f/yN0CJ2XFj+j
+pHs+Gw6WWSUDpybiiKnPec33BFawq3kyblnBMjBU61ioy5HwQqVkJ8vUVjGIUq3P
+vX/wBmQfzCe4o4uM89gpHyUL9UYGG8oCRa17dgqcv7u5rg0Wq2B1rgY+nHwx3JIv
+KRrgSwyRkGzpN8WQ1yrXlxWjgI9de0mPVDDUlywcWze1q2kwaEPTM3hLAmD1PESA
+oY/n8A/RXoeeRs9i/Pm/DGUS8ZPINXk/yOzsR/XvvkTVroIeLZqfmFpnZeF0cHzL
+08LODkVJJ9zjLdT7SA4vnne4FEbAxDbKAq5qkYzaL4UCAwEAAaOB0DCBzTAMBgNV
+HRMBAf8EAjAAMB0GA1UdDgQWBBSIWlXAUv9hzVKjNQ/qWpwkOCL3XDALBgNVHQ8E
+BAMCBeAwgZAGA1UdEQSBiDCBhYIeYWx0bnVsbC5weXRob24ub3JnAGV4YW1wbGUu
+Y29tgSBudWxsQHB5dGhvbi5vcmcAdXNlckBleGFtcGxlLm9yZ4YpaHR0cDovL251
+bGwucHl0aG9uLm9yZwBodHRwOi8vZXhhbXBsZS5vcmeHBMAAAgGHECABDbgAAAAA
+AAAAAAAAAAEwDQYJKoZIhvcNAQEFBQADggEBAKxPRe99SaghcI6IWT7UNkJw9aO9
+i9eo0Fj2MUqxpKbdb9noRDy2CnHWf7EIYZ1gznXPdwzSN4YCjV5d+Q9xtBaowT0j
+HPERs1ZuytCNNJTmhyqZ8q6uzMLoht4IqH/FBfpvgaeC5tBTnTT0rD5A/olXeimk
+kX4LxlEx5RAvpGB2zZVRGr6LobD9rVK91xuHYNIxxxfEGE8tCCWjp0+3ksri9SXx
+VHWBnbM9YaL32u3hxm8sYB/Yb8WSBavJCWJJqRStVRHM1koZlJmXNx2BX4vPo6iW
+RFEIPQsFZRLrtnCAiEhyT8bC2s/Njlu6ly9gtJZWSV46Q3ZjBL4q9sHKqZQ=
+-----END CERTIFICATE-----
diff -r e0f86c3b3685 Lib/test/test_ssl.py
--- a/Lib/test/test_ssl.py Sun Aug 11 13:04:50 2013 +0300
+++ b/Lib/test/test_ssl.py Sun Aug 11 18:17:23 2013 +0200
@@ -55,6 +55,7 @@
WRONGCERT = data_file("XXXnonexisting.pem")
BADKEY = data_file("badkey.pem")
NOKIACERT = data_file("nokia.pem")
+NULLBYTECERT = data_file("nullbytecert.pem")
DHFILE = data_file("dh512.pem")
BYTES_DHFILE = os.fsencode(DHFILE)
@@ -162,6 +163,27 @@
('DNS', 'projects.forum.nokia.com'))
)
+ def test_parse_cert_CVE_2013_4073(self):
+ p = ssl._ssl._test_decode_cert(NULLBYTECERT)
+ if support.verbose:
+ sys.stdout.write("\n" + pprint.pformat(p) + "\n")
+ subject = ((('countryName', 'US'),),
+ (('stateOrProvinceName', 'Oregon'),),
+ (('localityName', 'Beaverton'),),
+ (('organizationName', 'Python Software Foundation'),),
+ (('organizationalUnitName', 'Python Core Development'),),
+ (('commonName', 'null.python.org\x00example.org'),),
+ (('emailAddress', 'python-dev@python.org'),))
+ self.assertEqual(p['subject'], subject)
+ self.assertEqual(p['issuer'], subject)
+ self.assertEqual(p['subjectAltName'],
+ (('DNS', 'altnull.python.org\x00example.com'),
+ ('email', 'null@python.org\x00user@example.org'),
+ ('URI', 'http://null.python.org\x00http://example.org'),
+ ('IP Address', '192.0.2.1'),
+ ('IP Address', '2001:DB8:0:0:0:0:0:1\n'))
+ )
+
def test_DER_to_PEM(self):
with open(SVN_PYTHON_ORG_ROOT_CERT, 'r') as f:
pem = f.read()
@@ -294,6 +316,13 @@
fail(cert, 'foo.a.com')
fail(cert, 'bar.foo.com')
+ # NULL bytes are bad, CVE-2013-4073
+ cert = {'subject': ((('commonName',
+ 'null.python.org\x00example.org'),),)}
+ ok(cert, 'null.python.org\x00example.org') # or raise an error?
+ fail(cert, 'example.org')
+ fail(cert, 'null.python.org')
+
# Slightly fake real-world example
cert = {'notAfter': 'Jun 26 21:41:46 2011 GMT',
'subject': ((('commonName', 'linuxfrz.org'),),),
diff -r e0f86c3b3685 Modules/_ssl.c
--- a/Modules/_ssl.c Sun Aug 11 13:04:50 2013 +0300
+++ b/Modules/_ssl.c Sun Aug 11 18:17:23 2013 +0200
@@ -771,12 +771,14 @@
ext->value->length));
for(j = 0; j < sk_GENERAL_NAME_num(names); j++) {
-
/* get a rendering of each name in the set of names */
+ int gntype;
+ ASN1_STRING *as = NULL;
name = sk_GENERAL_NAME_value(names, j);
- if (name->type == GEN_DIRNAME) {
-
+ gntype = name-> type;
+ switch (gntype) {
+ case GEN_DIRNAME:
/* we special-case DirName as a tuple of
tuples of attributes */
@@ -798,11 +800,62 @@
goto fail;
}
PyTuple_SET_ITEM(t, 1, v);
+ break;
- } else {
+ case GEN_EMAIL:
+ case GEN_DNS:
+ case GEN_URI:
+ /* GENERAL_NAME_print() doesn't handle NUL bytes in ASN1_string
+ correctly. */
+ t = PyTuple_New(2);
+ if (t == NULL)
+ goto fail;
+ switch (gntype) {
+ case GEN_EMAIL:
+ v = PyUnicode_FromString("email");
+ as = name->d.rfc822Name;
+ break;
+ case GEN_DNS:
+ v = PyUnicode_FromString("DNS");
+ as = name->d.dNSName;
+ break;
+ case GEN_URI:
+ v = PyUnicode_FromString("URI");
+ as = name->d.uniformResourceIdentifier;
+ break;
+ }
+ if (v == NULL) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(t, 0, v);
+ v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_data(as),
+ ASN1_STRING_length(as));
+ if (v == NULL) {
+ Py_DECREF(t);
+ goto fail;
+ }
+ PyTuple_SET_ITEM(t, 1, v);
+ break;
+ default:
/* for everything else, we use the OpenSSL print form */
-
+ switch (gntype) {
+ /* check for new general name type */
+ case GEN_OTHERNAME:
+ case GEN_X400:
+ case GEN_EDIPARTY:
+ case GEN_IPADD:
+ case GEN_RID:
+ break;
+ default:
+ if (PyErr_WarnFormat(PyExc_RuntimeWarning, 1,
+ "Unknown general name type %d",
+ gntype) == -1) {
+ goto fail;
+ }
+ break;
+ }
(void) BIO_reset(biobuf);
GENERAL_NAME_print(biobuf, name);
len = BIO_gets(biobuf, buf, sizeof(buf)-1);
@@ -829,6 +882,7 @@
goto fail;
}
PyTuple_SET_ITEM(t, 1, v);
+ break;
}
/* and add that rendering to the list */

View File

@ -0,0 +1,41 @@
diff -r 7fa3e824a4ee Lib/py_compile.py
--- a/Lib/py_compile.py Tue Oct 29 22:25:06 2013 -0400
+++ b/Lib/py_compile.py Wed Oct 30 11:08:31 2013 +0100
@@ -108,15 +108,15 @@
byte-compile all installed files (or all files in selected
directories).
"""
- with tokenize.open(file) as f:
- try:
- st = os.fstat(f.fileno())
- except AttributeError:
- st = os.stat(file)
- timestamp = int(st.st_mtime)
- size = st.st_size & 0xFFFFFFFF
- codestring = f.read()
try:
+ with tokenize.open(file) as f:
+ try:
+ st = os.fstat(f.fileno())
+ except AttributeError:
+ st = os.stat(file)
+ timestamp = int(st.st_mtime)
+ size = st.st_size & 0xFFFFFFFF
+ codestring = f.read()
codeobject = builtins.compile(codestring, dfile or file, 'exec',
optimize=optimize)
except Exception as err:
diff -r 7fa3e824a4ee Lib/test/test_py_compile.py
--- a/Lib/test/test_py_compile.py Tue Oct 29 22:25:06 2013 -0400
+++ b/Lib/test/test_py_compile.py Wed Oct 30 11:08:31 2013 +0100
@@ -54,6 +54,10 @@
self.assertTrue(os.path.exists(self.pyc_path))
self.assertFalse(os.path.exists(self.cache_path))
+ def test_bad_coding(self):
+ bad_coding = os.path.join(os.path.dirname(__file__), 'bad_coding2.py')
+ self.assertIsNone(py_compile.compile(bad_coding, doraise=False))
+
def test_main():
support.run_unittest(PyCompileTests)

View File

@ -0,0 +1,188 @@
--- a/Doc/library/ssl.rst
+++ b/Doc/library/ssl.rst
@@ -283,10 +283,10 @@ Certificate handling
Verify that *cert* (in decoded format as returned by
:meth:`SSLSocket.getpeercert`) matches the given *hostname*. The rules
applied are those for checking the identity of HTTPS servers as outlined
- in :rfc:`2818`, except that IP addresses are not currently supported.
- In addition to HTTPS, this function should be suitable for checking the
- identity of servers in various SSL-based protocols such as FTPS, IMAPS,
- POPS and others.
+ in :rfc:`2818` and :rfc:`6125`, except that IP addresses are not currently
+ supported. In addition to HTTPS, this function should be suitable for
+ checking the identity of servers in various SSL-based protocols such as
+ FTPS, IMAPS, POPS and others.
:exc:`CertificateError` is raised on failure. On success, the function
returns nothing::
@@ -301,6 +301,13 @@ Certificate handling
.. versionadded:: 3.2
+ .. versionchanged:: 3.3.3
+ The function now follows :rfc:`6125`, section 6.4.3 and does neither
+ match multiple wildcards (e.g. ``*.*.com`` or ``*a*.example.org``) nor
+ a wildcard inside an internationalized domain names (IDN) fragment.
+ IDN A-labels such as ``www*.xn--pthon-kva.org`` are still supported,
+ but ``x*.python.org`` no longer matches ``xn--tda.python.org``.
+
.. function:: cert_time_to_seconds(timestring)
Returns a floating-point value containing a normal seconds-after-the-epoch
unchanged:
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -129,25 +129,53 @@ class CertificateError(ValueError):
pass
-def _dnsname_to_pat(dn, max_wildcards=1):
+def _dnsname_match(dn, hostname, max_wildcards=1):
+ """Matching according to RFC 6125, section 6.4.3
+
+ http://tools.ietf.org/html/rfc6125#section-6.4.3
+ """
pats = []
- for frag in dn.split(r'.'):
- if frag.count('*') > max_wildcards:
- # Issue #17980: avoid denials of service by refusing more
- # than one wildcard per fragment. A survery of established
- # policy among SSL implementations showed it to be a
- # reasonable choice.
- raise CertificateError(
- "too many wildcards in certificate DNS name: " + repr(dn))
- if frag == '*':
- # When '*' is a fragment by itself, it matches a non-empty dotless
- # fragment.
- pats.append('[^.]+')
- else:
- # Otherwise, '*' matches any dotless fragment.
- frag = re.escape(frag)
- pats.append(frag.replace(r'\*', '[^.]*'))
- return re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
+ if not dn:
+ return False
+
+ leftmost, *remainder = dn.split(r'.')
+
+ wildcards = leftmost.count('*')
+ if wildcards > max_wildcards:
+ # Issue #17980: avoid denials of service by refusing more
+ # than one wildcard per fragment. A survery of established
+ # policy among SSL implementations showed it to be a
+ # reasonable choice.
+ raise CertificateError(
+ "too many wildcards in certificate DNS name: " + repr(dn))
+
+ # speed up common case w/o wildcards
+ if not wildcards:
+ return dn.lower() == hostname.lower()
+
+ # RFC 6125, section 6.4.3, subitem 1.
+ # The client SHOULD NOT attempt to match a presented identifier in which
+ # the wildcard character comprises a label other than the left-most label.
+ if leftmost == '*':
+ # When '*' is a fragment by itself, it matches a non-empty dotless
+ # fragment.
+ pats.append('[^.]+')
+ elif leftmost.startswith('xn--') or hostname.startswith('xn--'):
+ # RFC 6125, section 6.4.3, subitem 3.
+ # The client SHOULD NOT attempt to match a presented identifier
+ # where the wildcard character is embedded within an A-label or
+ # U-label of an internationalized domain name.
+ pats.append(re.escape(leftmost))
+ else:
+ # Otherwise, '*' matches any dotless string, e.g. www*
+ pats.append(re.escape(leftmost).replace(r'\*', '[^.]*'))
+
+ # add the remaining fragments, ignore any wildcards
+ for frag in remainder:
+ pats.append(re.escape(frag))
+
+ pat = re.compile(r'\A' + r'\.'.join(pats) + r'\Z', re.IGNORECASE)
+ return pat.match(hostname)
def match_hostname(cert, hostname):
unchanged:
--- a/Lib/test/test_ssl.py
+++ b/Lib/test/test_ssl.py
@@ -307,11 +307,7 @@ class BasicSocketTests(unittest.TestCase
fail(cert, 'Xa.com')
fail(cert, '.a.com')
- cert = {'subject': ((('commonName', 'a.*.com'),),)}
- ok(cert, 'a.foo.com')
- fail(cert, 'a..com')
- fail(cert, 'a.com')
-
+ # only match one left-most wildcard
cert = {'subject': ((('commonName', 'f*.com'),),)}
ok(cert, 'foo.com')
ok(cert, 'f.com')
@@ -326,6 +322,36 @@ class BasicSocketTests(unittest.TestCase
fail(cert, 'example.org')
fail(cert, 'null.python.org')
+ # error cases with wildcards
+ cert = {'subject': ((('commonName', '*.*.a.com'),),)}
+ fail(cert, 'bar.foo.a.com')
+ fail(cert, 'a.com')
+ fail(cert, 'Xa.com')
+ fail(cert, '.a.com')
+
+ cert = {'subject': ((('commonName', 'a.*.com'),),)}
+ fail(cert, 'a.foo.com')
+ fail(cert, 'a..com')
+ fail(cert, 'a.com')
+
+ # wildcard doesn't match IDNA prefix 'xn--'
+ idna = 'püthon.python.org'.encode("idna").decode("ascii")
+ cert = {'subject': ((('commonName', idna),),)}
+ ok(cert, idna)
+ cert = {'subject': ((('commonName', 'x*.python.org'),),)}
+ fail(cert, idna)
+ cert = {'subject': ((('commonName', 'xn--p*.python.org'),),)}
+ fail(cert, idna)
+
+ # wildcard in first fragment and IDNA A-labels in sequent fragments
+ # are supported.
+ idna = 'www*.pythön.org'.encode("idna").decode("ascii")
+ cert = {'subject': ((('commonName', idna),),)}
+ ok(cert, 'www.pythön.org'.encode("idna").decode("ascii"))
+ ok(cert, 'www1.pythön.org'.encode("idna").decode("ascii"))
+ fail(cert, 'ftp.pythön.org'.encode("idna").decode("ascii"))
+ fail(cert, 'pythön.org'.encode("idna").decode("ascii"))
+
# Slightly fake real-world example
cert = {'notAfter': 'Jun 26 21:41:46 2011 GMT',
'subject': ((('commonName', 'linuxfrz.org'),),),
@@ -386,7 +412,7 @@ class BasicSocketTests(unittest.TestCase
cert = {'subject': ((('commonName', 'a*b.com'),),)}
ok(cert, 'axxb.com')
cert = {'subject': ((('commonName', 'a*b.co*'),),)}
- ok(cert, 'axxb.com')
+ fail(cert, 'axxb.com')
cert = {'subject': ((('commonName', 'a*b*.com'),),)}
with self.assertRaises(ssl.CertificateError) as cm:
ssl.match_hostname(cert, 'axxbxxc.com')
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -192,7 +192,7 @@ def match_hostname(cert, hostname):
san = cert.get('subjectAltName', ())
for key, value in san:
if key == 'DNS':
- if _dnsname_to_pat(value).match(hostname):
+ if _dnsname_match(value, hostname):
return
dnsnames.append(value)
if not dnsnames:
@@ -203,7 +203,7 @@ def match_hostname(cert, hostname):
# XXX according to RFC 2818, the most specific Common Name
# must be used.
if key == 'commonName':
- if _dnsname_to_pat(value).match(hostname):
+ if _dnsname_match(value, hostname):
return
dnsnames.append(value)
if len(dnsnames) > 1:

View File

@ -0,0 +1,37 @@
# HG changeset patch
# User Benjamin Peterson <benjamin@python.org>
# Date 1397442496 14400
# Node ID 4f15bd1ab28fe25c2e381ab05b11b60ce42fe613
# Parent b49d990aaa9d708a8c3174f6d51b8e069040ffe4# Parent 8130b8c066062bc589d337aebd3da4b156ee7f45
merge 3.2
diff --git a/Lib/test/test_json/test_decode.py b/Lib/test/test_json/test_decode.py
--- a/Lib/test/json_tests/test_decode.py
+++ b/Lib/test/json_tests/test_decode.py
@@ -70,5 +70,9 @@ class TestDecode:
msg = 'escape'
self.assertRaisesRegex(ValueError, msg, self.loads, s)
+ def test_negative_index(self):
+ d = self.json.JSONDecoder()
+ self.assertRaises(ValueError, d.raw_decode, 'a'*42, -50000)
+
class TestPyDecode(TestDecode, PyTest): pass
class TestCDecode(TestDecode, CTest): pass
diff --git a/Modules/_json.c b/Modules/_json.c
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -975,7 +975,10 @@ scan_once_unicode(PyScannerObject *s, Py
kind = PyUnicode_KIND(pystr);
length = PyUnicode_GET_LENGTH(pystr);
- if (idx >= length) {
+ if (idx < 0)
+ /* Compatibility with Python version. */
+ idx += length;
+ if (idx < 0 || idx >= length) {
PyErr_SetNone(PyExc_StopIteration);
return NULL;
}

View File

@ -0,0 +1,34 @@
# HG changeset patch
# User Benjamin Peterson <benjamin@python.org>
# Date 1402796473 25200
# Node ID 847e288d6e93dba049c280f40979e16a1378d0f6
# Parent 6f1f387759913d91cb307d2783b3a40c48fe7424# Parent 5676797f3a3eccaf38e2c500e77ed39c68923cc9
merge 3.3 (#21766)
diff --git a/Lib/http/server.py b/Lib/http/server.py
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -977,7 +977,7 @@ class CGIHTTPRequestHandler(SimpleHTTPRe
(and the next character is a '/' or the end of the string).
"""
- collapsed_path = _url_collapse_path(self.path)
+ collapsed_path = _url_collapse_path(urllib.parse.unquote(self.path))
dir_sep = collapsed_path.find('/', 1)
head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
if head in self.cgi_directories:
diff --git a/Lib/test/test_httpservers.py b/Lib/test/test_httpservers.py
--- a/Lib/test/test_httpservers.py
+++ b/Lib/test/test_httpservers.py
@@ -485,6 +485,11 @@ class CGIHTTPServerTestCase(BaseTestCase
(res.read(), res.getheader('Content-type'), res.status))
self.assertEqual(os.environ['SERVER_SOFTWARE'], signature)
+ def test_urlquote_decoding_in_cgi_check(self):
+ res = self.request('/cgi-bin%2ffile1.py')
+ self.assertEqual((b'Hello World\n', 'text/html', 200),
+ (res.read(), res.getheader('Content-type'), res.status))
+
class SocketlessRequestHandler(SimpleHTTPRequestHandler):
def __init__(self):

View File

@ -0,0 +1,21 @@
# This is a backport of following upstream patch:
# HG changeset patch
# User Serhiy Storchaka <storchaka@gmail.com>
# Date 1389272021 -7200
# Node ID 79ea4ce431b1b10c79f51dcb2aaa0ccb2a8b1d48
# Parent 9e3f5b5bcf7e4c62475bb1126fd0aecbbb9b64ac# Parent 0cf1defd5ac4433b8e36f950ba452103eb417f9f
Issue #20078: Reading malformed zipfiles no longer hangs with 100% CPU
consumption.
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -862,6 +862,8 @@ class ZipExtFile(io.BufferedIOBase):
data = self._fileobj.read(n)
self._compress_left -= len(data)
+ if not data:
+ raise EOFError
if self._decrypter is not None:
data = bytes(map(self._decrypter, data))

View File

@ -0,0 +1,102 @@
# This is a backport of following upstream patch:
# HG changeset patch
# User Benjamin Peterson <benjamin@python.org>
# Date 1396394277 14400
# Node ID 6370d44013f7e7e0892dd7f78b91d3a929e2d343
# Parent cb3a8abc0870d8d81a3521b3c8f397c5ccc73d7d# Parent 9186f4a18584f5038a9f875f2a7a3194ee46a571
merge 3.2 (#21082)
diff --git a/Doc/library/os.rst b/Doc/library/os.rst
--- a/Doc/library/os.rst
+++ b/Doc/library/os.rst
@@ -1563,11 +1563,8 @@ features:
The default *mode* is ``0o777`` (octal). On some systems, *mode* is
ignored. Where it is used, the current umask value is first masked out.
- If *exists_ok* is ``False`` (the default), an :exc:`OSError` is raised if
- the target directory already exists. If *exists_ok* is ``True`` an
- :exc:`OSError` is still raised if the umask-masked *mode* is different from
- the existing mode, on systems where the mode is used. :exc:`OSError` will
- also be raised if the directory creation fails.
+ If *exist_ok* is ``False`` (the default), an :exc:`OSError` is raised if the
+ target directory already exists.
.. note::
diff --git a/Lib/os.py b/Lib/os.py
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -230,23 +230,16 @@ SEEK_SET = 0
SEEK_CUR = 1
SEEK_END = 2
-
-def _get_masked_mode(mode):
- mask = umask(0)
- umask(mask)
- return mode & ~mask
-
# Super directory utilities.
# (Inspired by Eric Raymond; the doc strings are mostly his)
def makedirs(name, mode=0o777, exist_ok=False):
"""makedirs(path [, mode=0o777][, exist_ok=False])
- Super-mkdir; create a leaf directory and all intermediate ones.
- Works like mkdir, except that any intermediate path segment (not
- just the rightmost) will be created if it does not exist. If the
- target directory with the same mode as we specified already exists,
- raises an OSError if exist_ok is False, otherwise no exception is
+ Super-mkdir; create a leaf directory and all intermediate ones. Works like
+ mkdir, except that any intermediate path segment (not just the rightmost)
+ will be created if it does not exist. If the target directory already
+ exists, raise an OSError if exist_ok is False. Otherwise no exception is
raised. This is recursive.
"""
@@ -268,20 +261,7 @@ def makedirs(name, mode=0o777, exist_ok=
try:
mkdir(name, mode)
except OSError as e:
- dir_exists = path.isdir(name)
- expected_mode = _get_masked_mode(mode)
- if dir_exists:
- # S_ISGID is automatically copied by the OS from parent to child
- # directories on mkdir. Don't consider it being set to be a mode
- # mismatch as mkdir does not unset it when not specified in mode.
- actual_mode = st.S_IMODE(lstat(name).st_mode) & ~st.S_ISGID
- else:
- actual_mode = -1
- if not (e.errno == errno.EEXIST and exist_ok and dir_exists and
- actual_mode == expected_mode):
- if dir_exists and actual_mode != expected_mode:
- e.strerror += ' (mode %o != expected mode %o)' % (
- actual_mode, expected_mode)
+ if not exist_ok or e.errno != errno.EEXIST or not path.isdir(name):
raise
def removedirs(name):
diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py
--- a/Lib/test/test_os.py
+++ b/Lib/test/test_os.py
@@ -872,7 +872,7 @@ class MakedirTests(unittest.TestCase):
os.makedirs(path, mode)
self.assertRaises(OSError, os.makedirs, path, mode)
self.assertRaises(OSError, os.makedirs, path, mode, exist_ok=False)
- self.assertRaises(OSError, os.makedirs, path, 0o776, exist_ok=True)
+ os.makedirs(path, 0o776, exist_ok=True)
os.makedirs(path, mode=mode, exist_ok=True)
os.umask(old_mask)
@@ -898,9 +898,8 @@ class MakedirTests(unittest.TestCase):
os.makedirs(path, mode, exist_ok=True)
# remove the bit.
os.chmod(path, stat.S_IMODE(os.lstat(path).st_mode) & ~S_ISGID)
- with self.assertRaises(OSError):
- # Should fail when the bit is not already set when demanded.
- os.makedirs(path, mode | S_ISGID, exist_ok=True)
+ # May work even when the bit is not already set when demanded.
+ os.makedirs(path, mode | S_ISGID, exist_ok=True)
finally:
os.umask(old_mask)

View File

@ -0,0 +1,48 @@
"""Checks if all *.pyc and *.pyo files have later mtime than their *.py files."""
import imp
import os
import sys
# list of test and other files that we expect not to have bytecode
not_compiled = [
'test/bad_coding.py',
'test/bad_coding2.py',
'test/badsyntax_3131.py',
'test/badsyntax_future3.py',
'test/badsyntax_future4.py',
'test/badsyntax_future5.py',
'test/badsyntax_future6.py',
'test/badsyntax_future7.py',
'test/badsyntax_future8.py',
'test/badsyntax_future9.py',
'test/badsyntax_pep3120.py',
'lib2to3/tests/data/bom.py',
'lib2to3/tests/data/crlf.py',
'lib2to3/tests/data/different_encoding.py',
'lib2to3/tests/data/py2_test_grammar.py',
'.debug-gdb.py',
]
failed = 0
def bytecode_expected(source):
for f in not_compiled:
if source.endswith(f):
return False
return True
compiled = filter(lambda f: bytecode_expected(f), sys.argv[1:])
for f in compiled:
# check both pyo and pyc
to_check = map(lambda b: imp.cache_from_source(f, b), (True, False))
f_mtime = os.path.getmtime(f)
for c in to_check:
c_mtime = os.path.getmtime(c)
if c_mtime < f_mtime:
sys.stderr.write('Failed bytecompilation timestamps check: ')
sys.stderr.write('Bytecode file {} is older than source file {}.\n'.format(c, f))
failed += 1
if failed:
sys.stderr.write('\n{} files failed bytecompilation timestamps check.\n'.format(failed))
sys.exit(1)

View File

@ -0,0 +1,12 @@
--- Python-3.3.2/Lib/test/test_gdb.py.orig 2013-07-26 09:52:15.533852708 -0500
+++ Python-3.3.2/Lib/test/test_gdb.py 2013-07-26 15:07:53.733623014 -0500
@@ -729,8 +729,7 @@
foo\(1, 2, 3\)
''')
- @unittest.skipUnless(_thread,
- "Python was compiled without thread support")
+ @unittest.skip('Known failure on ARM: https://bugzilla.redhat.com/show_bug.cgi?id=986713')
def test_threads(self):
'Verify that "py-bt" indicates threads that are waiting for the GIL'
cmd = '''

View File

@ -57,7 +57,7 @@
%global with_systemtap 1
# some arches don't have valgrind so we need to disable its support on them
%ifarch %{ix86} x86_64 ppc %{power64} s390x
%ifarch %{ix86} x86_64 ppc %{power64} s390x %{arm}
%global with_valgrind 1
%else
%global with_valgrind 0
@ -126,7 +126,7 @@
Summary: Version 3 of the Python programming language aka Python 3000
Name: python3
Version: %{pybasever}.2
Release: 3%{?dist}
Release: 11%{?dist}
License: Python
Group: Development/Languages
@ -217,6 +217,10 @@ Source6: systemtap-example.stp
# Written by dmalcolm; not yet sent upstream
Source7: pyfuntop.stp
# A simple script to check timestamps of bytecode files
# Run in check section with Python that is currently being built
# Written by bkabrda
Source8: check-pyc-and-pyo-timestamps.py
# Fixup distutils/unixccompiler.py to remove standard library path from rpath:
# Was Patch0 in ivazquez' python3000 specfile:
@ -342,7 +346,9 @@ Patch137: 00137-skip-distutils-tests-that-fail-in-rpmbuild.patch
# http://bugs.python.org/issue8265 (rhbz#706253)
Patch139: 00139-skip-test_float-known-failure-on-arm.patch
# 00140 #
# ideally short lived patch disabling a test thats fragile on different arches
Patch140: python3-arm-skip-failing-fragile-test.patch
# Patch140: 00140-skip-test_ctypes-known-failure-on-sparc.patch does not appear
# to be relevant for python3
@ -602,6 +608,52 @@ Patch183: 00183-cve-2013-2099-fix-ssl-match_hostname-dos.patch
# We patch this by also accepting "#define ffi_wrapper_h"
Patch184: 00184-ctypes-should-build-with-libffi-multilib-wrapper.patch
# 00185 #
# Fix for CVE-2013-4238 --
# SSL module fails to handle NULL bytes inside subjectAltNames general names
# http://bugs.python.org/issue18709
# rhbz#996399
Patch185: 00185-CVE-2013-4238-hostname-check-bypass-in-SSL-module.patch
# 00186 #
# Fix for https://bugzilla.redhat.com/show_bug.cgi?id=1023607
# Fixes the problem of some *.py files not being bytecompiled properly
# during build. This was result of py_compile.compile raising exception
# when trying to convert test file with bad encoding, and thus not
# continuing bytecompilation for other files.
Patch186: 00186-dont-raise-from-py_compile.patch
# 00187 #
# Fix for rhbz#1023742
# Change behaviour of ssl.match_hostname() to follow RFC 6125
# See http://bugs.python.org/issue17997#msg194950 for more.
Patch187: 00187-change-match_hostname-to-follow-RFC-6125.patch
# 00188 #
# JSON module could read arbitrary process memory
# rhbz#1112293
Patch188: 00188-json-add-boundary-check.patch
# 00197
#
# The CGIHTTPServer Python module did not properly handle URL-encoded
# path separators in URLs. This may have enabled attackers to disclose a CGI
# script's source code or execute arbitrary scripts in the server's
# document root.
Patch197: 00197-fix-CVE-2014-4650.patch
# 00198
#
# Fix CVE-2013-7338: malformed ZIP files could cause 100% CPU usage
# https://hg.python.org/cpython/rev/79ea4ce431b1
Patch198: 00198-fix-CVE-2013-7338.patch
# 00199
#
# Fix CVE-2014-2667: os.makedirs(exist_ok=True) is not thread-safe in Python 3.x
# https://hg.python.org/cpython/rev/c24dd53ab4b9
Patch199: 00199-fix-CVE-2014-2667.patch
# (New patches go here ^^^)
#
@ -810,6 +862,7 @@ done
# 00138: not for python3
%ifarch %{arm}
%patch139 -p1
%patch140 -p1
%endif
# 00140: not for python3
%patch141 -p1
@ -860,6 +913,13 @@ done
# 00182: upstream as of Python 3.3.2
%patch183 -p1
%patch184 -p1
%patch185 -p1
%patch186 -p1
%patch187 -p1
%patch188 -p1
%patch197 -p1
%patch198 -p1
%patch199 -p1
# Currently (2010-01-15), http://docs.python.org/library is for 2.6, and there
# are many differences between 2.6 and the Python 3 library.
@ -1189,12 +1249,12 @@ iconv -f iso8859-1 -t utf-8 %{buildroot}/%{pylibdir}/Demo/rpc/README > README.co
# compile *.pyo
find %{buildroot} -type f -a -name "*.py" -print0 | \
LD_LIBRARY_PATH="%{buildroot}%{dynload_dir}/:%{buildroot}%{_libdir}" \
PYTHONPATH="%{buildroot}%{_libdir}python%{pybasever} %{buildroot}/%{_libdir}python%{pybasever}/site-packages" \
PYTHONPATH="%{buildroot}%{_libdir}/python%{pybasever} %{buildroot}%{_libdir}/python%{pybasever}/site-packages" \
xargs -0 %{buildroot}%{_bindir}/python%{pybasever} -O -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("%{buildroot}")[2]) for f in sys.argv[1:]]' || :
# compile *.pyc
find %{buildroot} -type f -a -name "*.py" -print0 | \
LD_LIBRARY_PATH="%{buildroot}%{dynload_dir}/:%{buildroot}%{_libdir}" \
PYTHONPATH="%{buildroot}%{_libdir}python%{pybasever} %{buildroot}/%{_libdir}python%{pybasever}/site-packages" \
PYTHONPATH="%{buildroot}%{_libdir}/python%{pybasever} %{buildroot}%{_libdir}/python%{pybasever}/site-packages" \
xargs -0 %{buildroot}%{_bindir}/python%{pybasever} -O -c 'import py_compile, sys; [py_compile.compile(f, dfile=f.partition("%{buildroot}")[2], optimize=0) for f in sys.argv[1:]]' || :
# Fixup permissions for shared libraries from non-standard 555 to standard 755:
@ -1276,6 +1336,13 @@ sed \
# ======================================================
%check
# first of all, check timestamps of bytecode files
find %{buildroot} -type f -a -name "*.py" -print0 | \
LD_LIBRARY_PATH="%{buildroot}%{dynload_dir}/:%{buildroot}%{_libdir}" \
PYTHONPATH="%{buildroot}%{_libdir}/python%{pybasever} %{buildroot}%{_libdir}/python%{pybasever}/site-packages" \
xargs -0 %{buildroot}%{_bindir}/python%{pybasever} %{SOURCE8}
topdir=$(pwd)
CheckPython() {
ConfName=$1
@ -1700,6 +1767,35 @@ rm -fr %{buildroot}
# ======================================================
%changelog
* Thu Dec 04 2014 Slavek Kabrda <bkabrda@redhat.com> - 3.3.2-19
- Fix CVE-2013-7338 and CVE-2014-2667.
Resolves: rhbz#1078015
Resolves: rhbz#1083594
* Mon Nov 03 2014 Slavek Kabrda <bkabrda@redhat.com> - 3.3.2-18
- Fix CVE-2014-4650 - CGIHTTPServer URL handling
Resolves: rhbz#1113529
* Mon Jun 30 2014 Matej Stuchlik <mstuchli@redhat.com> - 3.3.2-9
- JSON module could read arbitrary process memory
Resolves: rhbz#1112293
* Fri Nov 08 2013 Matej Stuchlik <mstuchli@redhat.com> - 3.3.2-8
- Changed behavior of ssl.match_hostname() to follow RFC 6125 (rhbz#1023742)
* Wed Oct 30 2013 Bohuslav Kabrda <bkabrda@redhat.com> - 3.3.2-7
- Bytecompile all *.py files properly during build (rhbz#1023607)
* Fri Aug 23 2013 Matej Stuchlik <mstuchli@redhat.com> - 3.3.2-6
- Added fix for CVE-2013-4238 (rhbz#996399)
* Fri Jul 26 2013 Dennis Gilmore <dennis@ausil.us> - 3.3.2-5
- fix up indentation in arm patch
* Fri Jul 26 2013 Dennis Gilmore <dennis@ausil.us> - 3.3.2-4
- disable a test that fails on arm
- enable valgrind support on arm arches
* Tue Jul 02 2013 Bohuslav Kabrda <bkabrda@redhat.com> - 3.3.2-3
- Fix build with libffi containing multilib wrapper for ffi.h (rhbz#979696).