-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,256 additions
and
173 deletions.
There are no files selected for viewing
129 changes: 0 additions & 129 deletions
129
tools/jenkins/include/patches/m4/m4-1.4.18-glibc-change-work-around.patch
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
.../jenkins/include/patches/python27/00351-cve-2019-20907-fix-infinite-loop-in-tarfile.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Rishi <rishi_devan@mail.com> | ||
Date: Wed, 15 Jul 2020 13:51:00 +0200 | ||
Subject: [PATCH] 00351-cve-2019-20907-fix-infinite-loop-in-tarfile.patch | ||
|
||
00351 # | ||
Avoid infinite loop when reading specially crafted TAR files using the tarfile module | ||
(CVE-2019-20907). | ||
See: https://bugs.python.org/issue39017 | ||
--- | ||
Lib/tarfile.py | 2 ++ | ||
Lib/test/recursion.tar | Bin 0 -> 516 bytes | ||
Lib/test/test_tarfile.py | 7 +++++++ | ||
.../2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst | 1 + | ||
4 files changed, 10 insertions(+) | ||
create mode 100644 Lib/test/recursion.tar | ||
create mode 100644 Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst | ||
|
||
diff --git a/Lib/tarfile.py b/Lib/tarfile.py | ||
index adf91d53823..574a6bb279d 100644 | ||
--- a/Lib/tarfile.py | ||
+++ b/Lib/tarfile.py | ||
@@ -1400,6 +1400,8 @@ class TarInfo(object): | ||
|
||
length, keyword = match.groups() | ||
length = int(length) | ||
+ if length == 0: | ||
+ raise InvalidHeaderError("invalid header") | ||
value = buf[match.end(2) + 1:match.start(1) + length - 1] | ||
|
||
keyword = keyword.decode("utf8") | ||
diff --git a/Lib/test/recursion.tar b/Lib/test/recursion.tar | ||
new file mode 100644 | ||
index 0000000000000000000000000000000000000000..b8237251964983f54ed1966297e887636cd0c5f4 | ||
GIT binary patch | ||
literal 516 | ||
zcmYdFPRz+kEn=W0Fn}74P8%Xw3X=l~85kIuo0>8xq$A1Gm}!7)KUsFc41m#O8A5+e | ||
I1_}|j06>QaCIA2c | ||
|
||
literal 0 | ||
HcmV?d00001 | ||
|
||
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py | ||
index 89bd738aea0..45921562f52 100644 | ||
--- a/Lib/test/test_tarfile.py | ||
+++ b/Lib/test/test_tarfile.py | ||
@@ -325,6 +325,13 @@ class CommonReadTest(ReadTest): | ||
class MiscReadTest(CommonReadTest): | ||
taropen = tarfile.TarFile.taropen | ||
|
||
+ def test_length_zero_header(self): | ||
+ # bpo-39017 (CVE-2019-20907): reading a zero-length header should fail | ||
+ # with an exception | ||
+ with self.assertRaisesRegexp(tarfile.ReadError, "file could not be opened successfully"): | ||
+ with tarfile.open(support.findfile('recursion.tar')) as tar: | ||
+ pass | ||
+ | ||
def test_no_name_argument(self): | ||
with open(self.tarname, "rb") as fobj: | ||
tar = tarfile.open(fileobj=fobj, mode=self.mode) | ||
diff --git a/Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst b/Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst | ||
new file mode 100644 | ||
index 00000000000..ad26676f8b8 | ||
--- /dev/null | ||
+++ b/Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst | ||
@@ -0,0 +1 @@ | ||
+Avoid infinite loop when reading specially crafted TAR files using the tarfile module (CVE-2019-20907). |
136 changes: 136 additions & 0 deletions
136
...patches/python27/00354-cve-2020-26116-http-request-method-crlf-injection-in-httplib.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: AMIR <31338382+amiremohamadi@users.noreply.github.com> | ||
Date: Sun, 19 Jul 2020 00:46:10 +0430 | ||
Subject: [PATCH] | ||
00354-cve-2020-26116-http-request-method-crlf-injection-in-httplib.patch | ||
|
||
00354 # | ||
Reject control chars in HTTP method in httplib.putrequest to prevent | ||
HTTP header injection | ||
|
||
Backported from Python 3.5-3.10 (and adjusted for py2's single-module httplib): | ||
- https://bugs.python.org/issue39603 | ||
- https://github.com/python/cpython/pull/18485 (3.10) | ||
- https://github.com/python/cpython/pull/21946 (3.5) | ||
|
||
Co-authored-by: AMIR <31338382+amiremohamadi@users.noreply.github.com> | ||
--- | ||
Lib/httplib.py | 16 +++++++ | ||
Lib/test/test_httplib.py | 46 +++++++++++++++++++ | ||
.../2020-02-12-14-17-39.bpo-39603.Gt3RSg.rst | 2 + | ||
3 files changed, 64 insertions(+) | ||
create mode 100644 Misc/NEWS.d/next/Security/2020-02-12-14-17-39.bpo-39603.Gt3RSg.rst | ||
|
||
diff --git a/Lib/httplib.py b/Lib/httplib.py | ||
index fcc4152aaf2..a63677477d5 100644 | ||
--- a/Lib/httplib.py | ||
+++ b/Lib/httplib.py | ||
@@ -257,6 +257,10 @@ _contains_disallowed_url_pchar_re = re.compile('[\x00-\x20\x7f-\xff]') | ||
# _is_allowed_url_pchars_re = re.compile(r"^[/!$&'()*+,;=:@%a-zA-Z0-9._~-]+$") | ||
# We are more lenient for assumed real world compatibility purposes. | ||
|
||
+# These characters are not allowed within HTTP method names | ||
+# to prevent http header injection. | ||
+_contains_disallowed_method_pchar_re = re.compile('[\x00-\x1f]') | ||
+ | ||
# We always set the Content-Length header for these methods because some | ||
# servers will otherwise respond with a 411 | ||
_METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT'} | ||
@@ -935,6 +939,8 @@ class HTTPConnection: | ||
else: | ||
raise CannotSendRequest() | ||
|
||
+ self._validate_method(method) | ||
+ | ||
# Save the method for use later in the response phase | ||
self._method = method | ||
|
||
@@ -1020,6 +1026,16 @@ class HTTPConnection: | ||
# On Python 2, request is already encoded (default) | ||
return request | ||
|
||
+ def _validate_method(self, method): | ||
+ """Validate a method name for putrequest.""" | ||
+ # prevent http header injection | ||
+ match = _contains_disallowed_method_pchar_re.search(method) | ||
+ if match: | ||
+ raise ValueError( | ||
+ "method can't contain control characters. %r " | ||
+ "(found at least %r)" | ||
+ % (method, match.group())) | ||
+ | ||
def _validate_path(self, url): | ||
"""Validate a url for putrequest.""" | ||
# Prevent CVE-2019-9740. | ||
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py | ||
index d8a57f73530..b5fec9aa1ec 100644 | ||
--- a/Lib/test/test_httplib.py | ||
+++ b/Lib/test/test_httplib.py | ||
@@ -385,6 +385,51 @@ class HeaderTests(TestCase): | ||
conn.putheader(name, value) | ||
|
||
|
||
+class HttpMethodTests(TestCase): | ||
+ def test_invalid_method_names(self): | ||
+ methods = ( | ||
+ 'GET\r', | ||
+ 'POST\n', | ||
+ 'PUT\n\r', | ||
+ 'POST\nValue', | ||
+ 'POST\nHOST:abc', | ||
+ 'GET\nrHost:abc\n', | ||
+ 'POST\rRemainder:\r', | ||
+ 'GET\rHOST:\n', | ||
+ '\nPUT' | ||
+ ) | ||
+ | ||
+ for method in methods: | ||
+ with self.assertRaisesRegexp( | ||
+ ValueError, "method can't contain control characters"): | ||
+ conn = httplib.HTTPConnection('example.com') | ||
+ conn.sock = FakeSocket(None) | ||
+ conn.request(method=method, url="/") | ||
+ | ||
+ | ||
+class HttpMethodTests(TestCase): | ||
+ def test_invalid_method_names(self): | ||
+ methods = ( | ||
+ 'GET\r', | ||
+ 'POST\n', | ||
+ 'PUT\n\r', | ||
+ 'POST\nValue', | ||
+ 'POST\nHOST:abc', | ||
+ 'GET\nrHost:abc\n', | ||
+ 'POST\rRemainder:\r', | ||
+ 'GET\rHOST:\n', | ||
+ '\nPUT' | ||
+ ) | ||
+ | ||
+ for method in methods: | ||
+ with self.assertRaisesRegexp( | ||
+ ValueError, "method can't contain control characters"): | ||
+ conn = httplib.HTTPConnection('example.com') | ||
+ conn.sock = FakeSocket(None) | ||
+ conn.request(method=method, url="/") | ||
+ | ||
+ | ||
+ | ||
class BasicTest(TestCase): | ||
def test_status_lines(self): | ||
# Test HTTP status lines | ||
@@ -1010,6 +1055,7 @@ class TunnelTests(TestCase): | ||
@test_support.reap_threads | ||
def test_main(verbose=None): | ||
test_support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest, | ||
+ HttpMethodTests, | ||
HTTPTest, HTTPSTest, SourceAddressTest, | ||
TunnelTests) | ||
|
||
diff --git a/Misc/NEWS.d/next/Security/2020-02-12-14-17-39.bpo-39603.Gt3RSg.rst b/Misc/NEWS.d/next/Security/2020-02-12-14-17-39.bpo-39603.Gt3RSg.rst | ||
new file mode 100644 | ||
index 00000000000..990affc3edd | ||
--- /dev/null | ||
+++ b/Misc/NEWS.d/next/Security/2020-02-12-14-17-39.bpo-39603.Gt3RSg.rst | ||
@@ -0,0 +1,2 @@ | ||
+Prevent http header injection by rejecting control characters in | ||
+http.client.putrequest(...). |
58 changes: 58 additions & 0 deletions
58
tools/jenkins/include/patches/python27/00355-CVE-2020-27619.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Charalampos Stratakis <cstratak@redhat.com> | ||
Date: Wed, 19 May 2021 15:20:30 +0200 | ||
Subject: [PATCH] 00355-CVE-2020-27619.patch | ||
|
||
00355 # | ||
No longer call eval() on content received via HTTP in the CJK codec tests | ||
Backported from the python3 branches upstream: https://bugs.python.org/issue41944 | ||
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1889886 | ||
|
||
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> | ||
Co-authored-by: Florian Bruhin <me@the-compiler.org> | ||
--- | ||
Lib/test/multibytecodec_support.py | 22 +++++++--------------- | ||
1 file changed, 7 insertions(+), 15 deletions(-) | ||
|
||
diff --git a/Lib/test/multibytecodec_support.py b/Lib/test/multibytecodec_support.py | ||
index 5b2329b6d84..53b5d64d453 100644 | ||
--- a/Lib/test/multibytecodec_support.py | ||
+++ b/Lib/test/multibytecodec_support.py | ||
@@ -279,30 +279,22 @@ class TestBase_Mapping(unittest.TestCase): | ||
self._test_mapping_file_plain() | ||
|
||
def _test_mapping_file_plain(self): | ||
- _unichr = lambda c: eval("u'\\U%08x'" % int(c, 16)) | ||
- unichrs = lambda s: u''.join(_unichr(c) for c in s.split('+')) | ||
+ def unichrs(s): | ||
+ return ''.join(unichr(int(x, 16)) for x in s.split('+')) | ||
urt_wa = {} | ||
|
||
with self.open_mapping_file() as f: | ||
for line in f: | ||
if not line: | ||
break | ||
- data = line.split('#')[0].strip().split() | ||
+ data = line.split('#')[0].split() | ||
if len(data) != 2: | ||
continue | ||
|
||
- csetval = eval(data[0]) | ||
- if csetval <= 0x7F: | ||
- csetch = chr(csetval & 0xff) | ||
- elif csetval >= 0x1000000: | ||
- csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \ | ||
- chr((csetval >> 8) & 0xff) + chr(csetval & 0xff) | ||
- elif csetval >= 0x10000: | ||
- csetch = chr(csetval >> 16) + \ | ||
- chr((csetval >> 8) & 0xff) + chr(csetval & 0xff) | ||
- elif csetval >= 0x100: | ||
- csetch = chr(csetval >> 8) + chr(csetval & 0xff) | ||
- else: | ||
+ if data[0][:2] != '0x': | ||
+ self.fail("Invalid line: {!r}".format(line)) | ||
+ csetch = bytes.fromhex(data[0][2:]) | ||
+ if len(csetch) == 1 and 0x80 <= csetch[0]: | ||
continue | ||
|
||
unich = unichrs(data[1]) |
Oops, something went wrong.