Commit Graph

27568 Commits

Author SHA1 Message Date
Senthil Kumaran f82e59ac40
[2.7] bpo-27973 - Fix for urllib.urlretrieve() failing on second ftp transfer (#1040)
* bpo-27973: Fix urllib.urlretrieve failing on subsequent ftp transfers from the same host.

* bpo-35411: Skip test_urllibnet FTP tests on Travis CI.
2019-12-30 21:14:56 -08:00
Miss Islington (bot) 5f2c1345a7
bpo-38295: prevent test_relative_path of test_py_compile failure on macOS Catalina (GH-17636)
(cherry picked from commit bf3aa1060a)

Co-authored-by: Ned Deily <nad@python.org>
2019-12-17 01:16:33 -08:00
Matthew Rollings a016d4e32c [2.7] bpo-38945: UU Encoding: Don't let newline in filename corrupt the output format (GH-17418). (#17452)
(cherry picked from commit a62ad4730c)

Co-authored-by: Matthew Rollings <1211162+stealthcopter@users.noreply.github.com>
2019-12-03 10:18:52 -08:00
Victor Stinner e649903303
bpo-38804: Fix REDoS in http.cookiejar (GH-17157) (GH-17345)
The regex http.cookiejar.LOOSE_HTTP_DATE_RE was vulnerable to regular
expression denial of service (REDoS).

LOOSE_HTTP_DATE_RE.match is called when using http.cookiejar.CookieJar
to parse Set-Cookie headers returned by a server.
Processing a response from a malicious HTTP server can lead to extreme
CPU usage and execution will be blocked for a long time.

The regex contained multiple overlapping \s* capture groups.
Ignoring the ?-optional capture groups the regex could be simplified to

    \d+-\w+-\d+(\s*\s*\s*)$

Therefore, a long sequence of spaces can trigger bad performance.

Matching a malicious string such as

    LOOSE_HTTP_DATE_RE.match("1-c-1" + (" " * 2000) + "!")

caused catastrophic backtracking.

The fix removes ambiguity about which \s* should match a particular
space.

You can create a malicious server which responds with Set-Cookie headers
to attack all python programs which access it e.g.

    from http.server import BaseHTTPRequestHandler, HTTPServer

    def make_set_cookie_value(n_spaces):
        spaces = " " * n_spaces
        expiry = f"1-c-1{spaces}!"
        return f"b;Expires={expiry}"

    class Handler(BaseHTTPRequestHandler):
        def do_GET(self):
            self.log_request(204)
            self.send_response_only(204)  # Don't bother sending Server and Date
            n_spaces = (
                int(self.path[1:])  # Can GET e.g. /100 to test shorter sequences
                if len(self.path) > 1 else
                65506  # Max header line length 65536
            )
            value = make_set_cookie_value(n_spaces)
            for i in range(99):  # Not necessary, but we can have up to 100 header lines
                self.send_header("Set-Cookie", value)
            self.end_headers()

    if __name__ == "__main__":
        HTTPServer(("", 44020), Handler).serve_forever()

This server returns 99 Set-Cookie headers. Each has 65506 spaces.
Extracting the cookies will pretty much never complete.

Vulnerable client using the example at the bottom of
https://docs.python.org/3/library/http.cookiejar.html :

    import http.cookiejar, urllib.request
    cj = http.cookiejar.CookieJar()
    opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
    r = opener.open("http://localhost:44020/")

The popular requests library was also vulnerable without any additional
options (as it uses http.cookiejar by default):

    import requests
    requests.get("http://localhost:44020/")

* Regression test for http.cookiejar REDoS

If we regress, this test will take a very long time.

* Improve performance of http.cookiejar.ISO_DATE_RE

A string like

"444444" + (" " * 2000) + "A"

could cause poor performance due to the 2 overlapping \s* groups,
although this is not as serious as the REDoS in LOOSE_HTTP_DATE_RE was.

(cherry picked from commit 1b779bfb85)
2019-11-24 16:49:23 +01:00
Serhiy Storchaka 493fef60a7
[2.7] bpo-38535: Fix positions for AST nodes for calls without arguments in decorators. (GH-16861). (GH-16931)
(cherry picked from commit 26ae9f6d3d)
2019-10-26 17:30:30 +03:00
Jason R. Coombs f5b1abbb3b [2.7] bpo-38216, bpo-36274: Allow subclasses to separately override validation and encoding behavior (GH-16476)
Backporting this change, I observe a couple of things:

1. The _encode_request call is no longer meaningful because the request construction will implicitly encode the request using the default encoding when the format string is used (request = '%s %s %s'...). In order to keep the code as consistent as possible, I decided to include the call as a pass-through. I'd be just as happy to remove it entirely, but I'll leave that up to the reviewer to decide. It's okay that this functionality is disabled on Python 2 because this functionality was mainly around bpo-36274, which was mainly a concern with the transition to Python 3.
2. Because _encode_request is no longer meaningful, neither is the test for it, so I've removed that test. Therefore, the meaningful part of this test is that for bpo-38216, adding a (underscore-protected) hook to customize/disable validation.

(cherry picked from commit 7774d7831e)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
2019-10-07 19:00:01 -07:00
Benjamin Peterson e7e58fe031
[2.7] bpo-37664: Update ensurepip bundled wheels, again (GH-16633)
(cherry picked from commit 10c452b894)

Co-authored-by: Pradyun Gedam <pradyunsg@gmail.com>
2019-10-07 18:54:05 -07:00
Victor Stinner 403ca7ea70
[2.7] bpo-38338, test.pythoninfo: add more ssl infos (GH-16543)
test.pythoninfo now logs environment variables used by OpenSSL and
Python ssl modules, and logs attributes of 3 SSL contexts
(SSLContext, default HTTPS context, stdlib context).

(cherry picked from commit 1df1c2f8df)
2019-10-02 18:36:32 +02:00
Dong-hee Na 8eb64155ff [2.7] bpo-38243: Escape the server title of DocXMLRPCServer (GH-16447)
Escape the server title of DocXMLRPCServer.DocXMLRPCServer
when rendering the document page as HTML.
2019-10-01 12:58:00 +02:00
Serhiy Storchaka be257bcad1
[2.7] bpo-38175: Fix a memory leak in comparison of sqlite3.Row objects. (GH-16155). (GH-16215)
(cherry picked from commit 8debfa5040)
2019-09-17 09:56:27 +03:00
Roberto C. Sánchez 4cbcd2f8c4 [2.7] bpo-34155: Dont parse domains containing @ (GH-13079) (GH-16006)
This change skips parsing of email addresses where domains include a "@" character, which can be maliciously used since the local part is returned as a complete address. 

(cherry picked from commit 8cb65d1381)

Excludes changes to Lib/email/_header_value_parser.py, which did not
exist in 2.7.

Co-authored-by: jpic <jpic@users.noreply.github.com>


https://bugs.python.org/issue34155
2019-09-14 10:26:38 -07:00
Zackery Spytz f9db011c32 closes bpo-36712: Fix duplicate method in Lib/email/test/test_email_renamed.py. (GH-14800) 2019-09-11 14:26:07 +01:00
Zackery Spytz b239ab9107 closes bpo-36711: Remove duplicate method in Lib/email/feedparser.py. (GH-14801) 2019-09-11 14:22:08 +01:00
Serhiy Storchaka 2fb6921ab2
[2.7] bpo-34410: Fix a crash in the tee iterator when re-enter it. (GH-15625) (GH-15740)
RuntimeError is now raised in this case.
(cherry picked from commit 526a01467b)
2019-09-09 12:38:05 +03:00
Miss Islington (bot) 0229b56d8c
closes bpo-37965: Fix compiler warning of distutils CCompiler.test_function. (GH-15560)
https://bugs.python.org/issue37965

https://bugs.python.org/issue37965

Automerge-Triggered-By: @benjaminp
(cherry picked from commit 55aabee075)

Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
2019-08-28 10:36:18 -07:00
Victor Stinner 3b26f734c0
test_multiprocessing removes temporary files (GH-15421)
(cherry picked from commit d0b10a6435)
2019-08-23 13:59:40 +01:00
Miss Islington (bot) 198a0d622a
bpo-35518: Skip test that relies on a deceased network service. (GH-15349)
If this service had thoroughly vanished, we could just ignore the
test until someone gets around to either recreating such a service
or redesigning the test to somehow work locally.  The
`support.transient_internet` mechanism catches the failure to
resolve the domain name, and skips the test.

But in fact the domain snakebite.net does still exist, as do its
nameservers -- and they can be quite slow to reply.  As a result
this test can easily take 20-30s before it gets auto-skipped.

So, skip the test explicitly up front.
(cherry picked from commit 5b95a1507e)

Co-authored-by: Greg Price <gnprice@gmail.com>
2019-08-20 21:12:18 -07:00
Miss Islington (bot) 53639dd55a
closes bpo-37675: Use pkgutil.iter_modules to find fixers in a package rather than listdir. (14942)
(cherry picked from commit 93e8aa62cf)

Co-authored-by: Benjamin Peterson <benjamin@python.org>
2019-07-24 16:59:31 -07:00
Miss Islington (bot) bc60c47169
[2.7] bpo-30754: Document textwrap.dedent blank line behavior. (GH-14469) (GH-14475)
* Added documentation for textwrap.dedent behavior.
(cherry picked from commit eb97b9211e)


Co-authored-by: tmblweed <tmblweed@users.noreply.github.com>


https://bugs.python.org/issue30754
2019-06-29 21:41:55 -07:00
Miss Islington (bot) dfa9499ccb [2.7] bpo-37411: Rewrite test_wsgiref.testEnviron() (GH-14394) (GH-14404)
Fix test_wsgiref.testEnviron() to no longer depend on the environment
variables (don't fail if "X" variable is set).

testEnviron() now overrides os.environ to get a deterministic
environment. Test full TestHandler.environ content: not only a few
selected variables.
(cherry picked from commit 5150d32792)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
2019-06-26 22:54:27 +02:00
Victor Stinner 6cbff564f0
bpo-37124: Fix reference leak in test_msilib (GH-13750) (GH-14340)
(cherry picked from commit c0295dba25)
2019-06-24 16:09:49 +02:00
Victor Stinner 9d55bf440c
bpo-37359: Add --cleanup option to python3 -m test (GH-14332) (GH-14333)
* regrtest: Add --cleanup option to remove "test_python_*" directories
  of previous failed test jobs.
* Add "make cleantest" to run "python -m test --cleanup".

(cherry picked from commit 47fbc4e45b)
2019-06-24 13:21:18 +02:00
Miss Islington (bot) 0346448396
Improve threading.daemon docstring (GH-14278)
Rephrase and clarify that "the entire Python program exits when only daemon threads are left". This matches the documentation at https://docs.python.org/3/library/threading.htmlGH-thread-objects.
(cherry picked from commit bb110cc2ed)

Co-authored-by: mbarkhau <mbarkhau@gmail.com>
2019-06-23 12:08:28 -07:00
Victor Stinner adcdb1e4f5
bpo-37362: test_gdb now ignores stderr (GH-14287) (GH-14297)
test_gdb no longer fails if it gets an "unexpected" message on
stderr: it now ignores stderr. The purpose of test_gdb is to test
that python-gdb.py commands work as expected, not to test gdb.

(cherry picked from commit e56a123fd0)
2019-06-21 23:58:53 +02:00
Terry Jan Reedy 722733e940
[2.7] Fix 2.7 test -R test_IDLE failure on Windows (GH-13958)
Cherry-picked from 66d47da.
2019-06-16 16:36:23 -04:00
Xtreak ee15aa2b85 [2.7] bpo-35647: Fix path check in cookiejar. (GH-11436) (GH-13427) 2019-06-15 19:29:29 +03:00
Xtreak 979daae300 [2.7] bpo-35121: prefix dot in domain for proper subdomain validation (GH-10258) (GH-13426)
This is a manual backport of ca7fe50635 since 2.7 has `http.cookiejar` in `cookielib`


https://bugs.python.org/issue35121
2019-06-15 08:29:43 -07:00
Victor Stinner 2b578479b9
[2.7] bpo-36742: Fix urlparse.urlsplit() error message for Unicode URL (GH-13937)
If urlparse.urlsplit() detects an invalid netloc according to NFKC
normalization, the error message type is now str rather than unicode,
and use repr() to format the URL, to prevent <exception str() failed>
when display the error message.
2019-06-11 12:45:35 +02:00
Eric Wieser 48f190f79c [2.7] bpo-37188: Fix a divide-by-zero in arrays of size-0 objects (#13906) 2019-06-08 11:19:24 +02:00
Tal Einat 1b57ab5c64
[2.7] bpo-37177: make IDLE's search dialogs transient (GH-13869)
This avoids the search dialogs being hidden behind the editor window.

(cherry picked from commit 554450fb4e)
2019-06-07 09:53:05 +03:00
Steve Dower f61599b050
bpo-36742: Corrects fix to handle decomposition in usernames (GH-13812) 2019-06-04 09:40:16 -07:00
Miss Islington (bot) bfc1f60560 [2.7] bpo-12639: msilib.Directory.start_component() fails if *keyfile* is not None (GH-13688)
* bpo-12639: msilib.Directory.start_component() fails if *keyfile* is not None (GH-13688)

msilib.Directory.start_component() was passing an extra argument to CAB.gen_id().
(cherry picked from commit c8d5bf6c3f)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
2019-05-31 15:39:39 -07:00
Victor Stinner aaed2c332a
bpo-26423: Fix test_descr.test_wrap_lenfunc_bad_cast() on 32-bit Windows (GH-13629)
Skip the test if xrange(sys.maxsize) raises an OverflowError.
2019-05-28 18:15:30 +02:00
Victor Stinner 80dfe99016
bpo-26423: Fix possible overflow in wrap_lenfunc() (GH-13606) (GH-13625)
Fix possible overflow in wrap_lenfunc() when
sizeof(long) < sizeof(Py_ssize_t) (e.g., 64-bit Windows).

(cherry picked from commit 05f16416d9)
2019-05-28 17:23:07 +02:00
Michele Angrisano 25d8404c35 bpo-36713: Rename duplicated method in test_unicode. (#13525)
modified:   Lib/ctypes/test/test_unicode.py
 	modified:   Misc/ACKS
 	new file:   Misc/NEWS.d/next/Library/2019-05-23-15-57-36.bpo-36713.sjPhnf.rst
2019-05-23 16:42:50 +02:00
Victor Stinner 942c31dffb
bpo-35907: Complete test_urllib.test_local_file_open() (GH-13506)
Test also URLopener().open(), URLopener().retrieve(), and
DummyURLopener().retrieve().
2019-05-22 23:28:03 +02:00
SH b15bde8058 bpo-35907, CVE-2019-9948: urllib rejects local_file:// scheme (GH-11842)
CVE-2019-9948: Avoid file reading as disallowing the unnecessary URL scheme in urllib.urlopen().
2019-05-21 23:12:23 +02:00
Victor Stinner bb8071a4ca
bpo-30458: Disallow control chars in http URLs (GH-12755) (GH-13154) (GH-13315)
Disallow control chars in http URLs in urllib2.urlopen.  This
addresses a potential security problem for applications that do not
sanity check their URLs where http request headers could be injected.

Disable https related urllib tests on a build without ssl (GH-13032)
These tests require an SSL enabled build. Skip these tests when
python is built without SSL to fix test failures.

Use httplib.InvalidURL instead of ValueError as the new error case's
exception. (GH-13044)

Backport Co-Authored-By: Miro Hrončok <miro@hroncok.cz>

(cherry picked from commit 7e200e0763)

Notes on backport to Python 2.7:

* test_urllib tests urllib.urlopen() which quotes the URL and so is
  not vulerable to HTTP Header Injection.
* Add tests to test_urllib2 on urllib2.urlopen().
* Reject non-ASCII characters: range 0x80-0xff.
2019-05-21 15:12:33 +02:00
Terry Jan Reedy c841a30879
[2.7] Update idlelib NEWS.txt for 2.7 (GH-13436) 2019-05-19 22:35:21 -04:00
Benjamin Peterson 951af2d7f1
closes bpo-36755: Suppress noisy error output in test HTTPS server by default. (GH-13370)
TLS 1.3 has a more efficient handshake protocol. The client can reject the server's credentials and close the connection before the server has even finished writing out all of its initial data. Depending on whether the server finishes writing the rest of its handshake before the it sees the connection is reset, the server will read an empty line or see a ECONNRESET OSError. Nothing is really wrong here with the server or client, so just suppress the error output in the OSError case to fix the test.

This fix isn't required in Python 3 because clients that reject the server's certificate will shut down the TLS layer before closing the TCP connection.
2019-05-17 11:29:38 -07:00
Terry Jan Reedy 353f8d2282
[2.7] bpo-36807: When saving a file in IDLE, call flush and fsync (GH-13102) (GH-13293) 2019-05-13 18:29:15 -04:00
Gregory P. Smith 7346a16ed5
[2.7] bpo-35925: Skip SSL tests that fail due to weak external certs or old TLS (GH-13124) (GH-13253)
Modern Linux distros such as Debian Buster have default OpenSSL system
configurations that reject connections to servers with weak certificates
by default. This causes our test suite run with external networking
resources enabled to skip these tests when they encounter such a
failure.

Fixing the network servers is a separate issue.
(cherry picked from commit 2cc0223)

Changes to test_ssl.py required as 2.7 has legacy protocol tests.

The test_httplib.py change is omitted from this backport as
self-signed.pythontest.net's certificate was updated and the
test_nntplib.py change is not applicable on 2.7.

Authored-by: Gregory P. Smith greg@krypto.org
2019-05-13 13:16:34 -07:00
Gregory P. Smith 7b5dca8345
[2.7] bpo-36816: Update the self-signed.pythontest.net cert (GH-13192) (GH-13199)
* [2.7] bpo-36816: Update the self-signed.pythontest.net cert (GH-13192)

We updated the server, our testsuite must match.

https://bugs.python.org/issue36816

✈️ CLE -> DEN ✈️ #pycon2019 #beyonce
(cherry picked from commit 6bd81734de)

The 2.7 tree also needed a certificate in the capath directory updated.
The filename for that was determined by `openssl x509 -in $cert.pem -subject_hash`.

Authored-by: Gregory P. Smith <greg@krypto.org>
2019-05-08 18:53:15 -06:00
Zackery Spytz 7c2c01f02a [2.7] bpo-14546: Fix the argument handling in Tools/scripts/lll.py (GH-13026) (GH-13063)
(cherry picked from commit c4e78b116f)
2019-05-02 15:29:21 -04:00
Miss Islington (bot) 74852b9794
Change bisect to bisect_cmd in docstring (GH-13040)
(cherry picked from commit 11e4a941e9)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
2019-05-01 20:01:41 -07:00
Steve Dower 98a4dcefbb
bpo-36742: Fixes handling of pre-normalization characters in urlsplit() (GH-13017) 2019-05-01 15:00:27 +00:00
Victor Stinner be6cbfb767
bpo-35952: Sync test.pythoninfo from master (GH-13010) 2019-04-29 15:20:38 +02:00
Victor Stinner f4edd39017
bpo-28552: Fix distutils.sysconfig for empty sys.executable (GH-12875) (GH-12949)
bpo-28552, bpo-7774: Fix distutils.sysconfig if sys.executable is
None or an empty string: use os.getcwd() to initialize project_base.

Fix also the distutils build command: don't use sys.executable if
it's evaluated as false (None or empty string).
2019-04-25 13:16:02 +02:00
Victor Stinner 22de4ce498
bpo-36235: Fix distutils test_customize_compiler() on macOS (GH-12751)
Set CUSTOMIZED_OSX_COMPILER to True to disable
_osx_support.customize_compiler().
2019-04-09 19:54:10 +02:00
Victor Stinner 9c14061a2c
bpo-36560: Fix reference leak hunting in regrtest (GH-12744) (GH-12745)
Fix reference leak hunting in regrtest: compute also deltas (of
reference count and file descriptor count) during warmup, to ensure
that everything is initialized before starting to hunt reference
leaks.

Other changes:

* Replace gc.collect() with support.gc_collect() in clear_caches()
* dash_R() is now more quiet with --quiet option (don't display
  progress).
* Precompute the full range for "for it in range(repcount):" to
  ensure that the iteration doesn't allocate anything new.
* dash_R() now is responsible to call warm_caches().

(cherry picked from commit 5aaac94eeb)
2019-04-09 18:01:17 +02:00