Commit Graph

6275 Commits

Author SHA1 Message Date
Victor Stinner 8b83687bdf bpo-28129: fix ctypes crashes (#386) (#3800)
* init commit, with initial tests for from_param and fields __set__ and __get__, and some additions to from_buffer and from_buffer_copy

* added the rest of tests and patches. probably only a first draft.

* removed trailing spaces

* replace ctype with ctypes in error messages

* change back from ctypes instance to ctype instance

(cherry picked from commit 1bea762d9e)
2017-09-28 07:31:40 -07:00
Miss Islington (bot) 9bfa55bfea [2.7] bpo-31490: Fix an assertion failure in ctypes in case an _anonymous_ attr is defined only outside _fields_. (GH-3615) (#3780)
(cherry picked from commit 30b61b51e0)
2017-09-27 09:52:44 +03:00
Serhiy Storchaka 81691b0548 [2.7] bpo-31311: Fix a SystemError and a crash in ctypes._CData.__setstate__(), in case of a bad __dict__. (GH-3254). (#3781)
(cherry picked from commit 57c2561c8c)
2017-09-27 09:24:39 +03:00
Serhiy Storchaka 4954b8dc53 [2.7] bpo-25359: Add missed "goto error" after setting an exception. (GH-3712) (#3779)
(cherry picked from commit d6238a76c6)
2017-09-27 08:44:03 +03:00
Serhiy Storchaka d0b9dc3367 [2.7] bpo-30347: Stop crashes when concurrently iterate over itertools.groupby() iterators. (GH-1557). (#3772)
(cherry picked from commit c740e4fe8a)
2017-09-26 23:15:36 +03:00
Benjamin Peterson a72d15c97f consistently use Py_TYPE, Py_REFCNT, and correct initializer macros (#3563)
This no-op change makes 2.7 more consistent with 3.x to ease comparison and backports.
2017-09-13 21:20:29 -07:00
Christian Heimes b9a860f3bf [2.7] bpo-29136: Add TLS 1.3 cipher suites and OP_NO_TLSv1_3 (GH-1363) (#3446)
* bpo-29136: Add TLS 1.3 support

TLS 1.3 introduces a new, distinct set of cipher suites. The TLS 1.3
cipher suites don't overlap with cipher suites from TLS 1.2 and earlier.
Since Python sets its own set of permitted ciphers, TLS 1.3 handshake
will fail as soon as OpenSSL 1.1.1 is released. Let's enable the common
AES-GCM and ChaCha20 suites.

Additionally the flag OP_NO_TLSv1_3 is added. It defaults to 0 (no op) with
OpenSSL prior to 1.1.1. This allows applications to opt-out from TLS 1.3
now.

Signed-off-by: Christian Heimes <christian@python.org>.
(cherry picked from commit cb5b68abde)
2017-09-07 22:31:17 -07:00
Christian Heimes 611a3eab19 [2.7] bpo-28958: Improve SSLContext error reporting. (GH-3414) (#3433)
Signed-off-by: Christian Heimes <christian@python.org>
(cherry picked from commit 17c9ac9)
2017-09-07 16:45:07 -07:00
Benjamin Peterson eba0bad310 Merge branch 'release-2.7.14' into 2.7 2017-09-05 18:06:20 -07:00
Victor Stinner c00d5087cd bpo-31170: Update libexpat from 2.2.3 to 2.2.4 (#3315)
Fix copying of partial characters for UTF-8 input (libexpat bug 115):
https://github.com/libexpat/libexpat/issues/115

(cherry picked from commit 759e30ec47)

The standard header stdbool.h is not available
with old Visual Studio compilers

Cherry-picked from libexpat b4b89c2ab0cc5325a41360c25ef9d2ccbe617e5c.

expat: Add artificial scopes in xmltok.c utf8_toUtf8() to fix c89 compilation.

Cherry-picked from libexpat commit e0b290eb3d8f4c4b45137a7d7f4f8db812145bd2
2017-09-05 18:04:39 -07:00
Victor Stinner eeadf5fc23 bpo-31339: Rewrite time.asctime() and time.ctime() (#3293)
* bpo-31339: Rewrite time.asctime() and time.ctime()

Backport and adapt the _asctime() function from the master branch to
not depend on the implementation of asctime() and ctime() from the
external C library. This change fixes a bug when Python is run using
the musl C library.

* bound checks for time.asctime()

* bound checks for time.strftime()
2017-09-06 01:35:39 +02:00
Christian Heimes c9d668c0d8 [2.7] bpo-30502: Fix handling of long oids in ssl. (GH-2909). (#3322)
(cherry picked from commit e503ca5288)
2017-09-05 19:13:07 +02:00
Christian Heimes 7daa45db1d [2.7] bpo-30102: Call OPENSSL_add_all_algorithms_noconf (GH-3112) (#3343)
The ssl and hashlib modules now call OPENSSL_add_all_algorithms_noconf() on
OpenSSL < 1.1.0. The function detects CPU features and enables optimizations
on some CPU architectures such as POWER8. Patch is based on research from
Gustavo Serra Scalet.

Signed-off-by: Christian Heimes <christian@python.org>
(cherry picked from commit c941e62)
2017-09-05 17:12:12 +02:00
Christian Heimes ffa7011cb9 [2.7] bpo-31343: Include sys/sysmacros.h (GH-3318) (#3345)
Include sys/sysmacros.h for major(), minor(), and makedev(). GNU C libray
plans to remove the functions from sys/types.h.

Signed-off-by: Christian Heimes <christian@python.org>.
(cherry picked from commit 75b961869a)
2017-09-05 17:08:45 +02:00
Christian Heimes 72ed233167 [2.7] bpo-30622: Change NPN detection: (GH-2079) (#3316)
* Change NPN detection:

Version breakdown, support disabled (pre-patch/post-patch):
- pre-1.0.1: OPENSSL_NPN_NEGOTIATED will not be defined -> False/False
- 1.0.1 and 1.0.2: OPENSSL_NPN_NEGOTIATED will not be defined ->
False/False
- 1.1.0+: OPENSSL_NPN_NEGOTIATED will be defined and
OPENSSL_NO_NEXTPROTONEG will be defined -> True/False

Version breakdown support enabled (pre-patch/post-patch):
- pre-1.0.1: OPENSSL_NPN_NEGOTIATED will not be defined -> False/False
- 1.0.1 and 1.0.2: OPENSSL_NPN_NEGOTIATED will be defined and
OPENSSL_NO_NEXTPROTONEG will not be defined -> True/True
- 1.1.0+: OPENSSL_NPN_NEGOTIATED will be defined and
OPENSSL_NO_NEXTPROTONEG will not be defined -> True/True

* Refine NPN guard:

- If NPN is disabled, but ALPN is available we need our callback
- Make clinic's ssl behave the same way

This created a working ssl module for me, with NPN disabled and ALPN
enabled for OpenSSL 1.1.0f.

Concerns to address:
The initial commit for NPN support into OpenSSL [1], had the
OPENSSL_NPN_* variables defined inside the OPENSSL_NO_NEXTPROTONEG
guard. The question is if that ever made it into a release.
This would need an ugly hack, something like:

	GH-if defined(OPENSSL_NO_NEXTPROTONEG) && \
		!defined(OPENSSL_NPN_NEGOTIATED)
	GH-	define OPENSSL_NPN_UNSUPPORTED 0
	GH-	define OPENSSL_NPN_NEGOTIATED 1
	GH-	define OPENSSL_NPN_NO_OVERLAP 2
	GH-endif

[1] https://github.com/openssl/openssl/commit/68b33cc5c7.
(cherry picked from commit b2d096bd2a)
2017-09-05 01:11:40 +02:00
INADA Naoki 4cde4bdcc8 bpo-31095: Fix potential crash during GC (GH-3197)
(cherry picked from commit a6296d34a4)
2017-09-04 12:31:41 +09:00
Pauli Virtanen 990b2d043c [2.7] bpo-10746: Fix ctypes PEP 3118 type codes for c_long, c_bool, c_int (GH-31) (#3242)
[2.7] bpo-10746: Fix ctypes PEP 3118 type codes for c_long, c_bool, c_int (GH-31)

Ctypes currently produces wrong pep3118 type codes for several types.
E.g. memoryview(ctypes.c_long()).format gives "<l" on 64-bit platforms,
but it should be "<q" instead for sizeof(c_long) == 8

The problem is that the '<>' endian specification in the struct syntax
also turns on the "standard size" mode, which makes type characters have
a platform-independent meaning, which does not match with the codes used
internally in ctypes.  The struct module format syntax also does not
allow specifying native-size non-native-endian items.

This commit adds a converter function that maps the internal ctypes
codes to appropriate struct module standard-size codes in the pep3118
format strings. The tests are modified to check for this..
(cherry picked from commit 07f1658aa0)
2017-09-02 18:24:32 +02:00
Oren Milman 20958e6d91 [2.7] bpo-31243: Fixed PyArg_ParseTuple failure checks. (GH-3171) (#3235) 2017-08-29 19:16:12 +03:00
Oren Milman bc80fd1bd2 [2.7] bpo-28261: Prevent raising SystemError where PyArg_ParseTuple is used to parse non-args. (#3213) 2017-08-26 21:56:31 +03:00
Victor Stinner ec4ab09b7c bpo-30947: Update libexpat from 2.2.1 to 2.2.3 (#3106) (#3145)
* bpo-30947: Update libexpat from 2.2.1 to 2.2.3

* Add NEWS entry

* Add new loadlibrary.c

* expat_external.h: restore include "pyexpatns.h"

* PCbuild: add expat/loadlibrary.c

* Define XML_POOR_ENTROPY to compile expat

Python 2.7 backport: add expat/loadlibrary.c to PC/VS9.0/ project
files (_elementtree and pyexpat).

(cherry picked from commit 93d0cb58b4)
2017-08-19 01:06:45 +02:00
Victor Stinner 4dea06531e bpo-31173: Rewrite WSTOPSIG test of test_subprocess (#3055) (#3071)
The current test_child_terminated_in_stopped_state() function test
creates a child process which calls ptrace(PTRACE_TRACEME, 0, 0) and
then crash (SIGSEGV). The problem is that calling os.waitpid() in the
parent process is not enough to close the process: the child process
remains alive and so the unit test leaks a child process in a
strange state. Closing the child process requires non-trivial code,
maybe platform specific.

Remove the functional test and replaces it with an unit test which
mocks os.waitpid() using a new _testcapi.W_STOPCODE() function to
test the WIFSTOPPED() path.
(cherry picked from commit 7b7c6dcfff)
2017-08-11 14:38:37 +02:00
Segev Finer 884c4ca33a [2.7] bpo-30797: Avoid _GNU_SOURCE redefined warning in xmlparse.c (GH-2670) (#2672)
* [2.7] Avoid _GNU_SOURCE redefined warning in xmlparse.c (GH-2670)
(cherry picked from commit f52325598e)

* [2.7] Avoid _GNU_SOURCE redefined warning in xmlparse.c (GH-2670).
(cherry picked from commit f52325598e)
2017-07-12 00:16:28 +02:00
Nir Soffer bfa4fe4f39 [2.7] bpo-29854: Fix segfault in call_readline() (GH-728)
If history-length is set in .inputrc, and the history file is double the
history size (or more), history_get(N) returns NULL, and python
segfaults. Fix that by checking for NULL return value.

It seems that the root cause is incorrect handling of bigger history in
readline, but Python should not segfault even if readline returns
unexpected value.

This issue affects only GNU readline. When using libedit emulation
system history size option does not work.

This is a backport of the actual fix from master without the test, since
the test depends on new run_pty() helper which is not available in 2.7.
2017-07-11 00:06:57 +03:00
Antoine Pitrou a45a99b47f [2.7] bpo-30807: signal.setitimer() may disable the timer by mistake (GH-2493) (#2499)
* bpo-30807: signal.setitimer() may disable the timer by mistake

* Add NEWS blurb.
(cherry picked from commit 729780a810)
2017-06-30 10:54:54 +02:00
Victor Stinner 95a91df036 bpo-30764: Windows support.SuppressCrashReport (#2423)
* Add Windows support to test.support.SuppressCrashReport: call
  SetErrorMode() and CrtSetReportMode().
* _testcapi: add CrtSetReportMode() and CrtSetReportFile() functions
  and CRT_xxx and CRTDBG_xxx constants needed by SuppressCrashReport.
2017-06-27 14:31:40 +02:00
Serhiy Storchaka 787826c931 [2.7] bpo-30746: Prohibited the '=' character in environment variable names (GH-2382) (#2393)
in `os.putenv()` and `os.spawn*()`..
(cherry picked from commit 77703942c5)
2017-06-25 09:50:00 +03:00
Serhiy Storchaka 9dda2caca8 [2.7] bpo-30730: Prevent environment variables injection in subprocess on Windows. (GH-2325) (#2372)
Prevent passing other invalid environment variables and command arguments..
(cherry picked from commit d174d24a5d)
2017-06-24 11:49:00 +03:00
Victor Stinner 2ada64d2a0 [2.7] bpo-30694: Upgrade Modules/expat/ to libexpat 2.2.1 (#2300) (#2312)
* bpo-30694: Upgrade Modules/expat/ to libexpat 2.2.1 (#2300)

New file: Modules/expat/siphash.h.
(cherry picked from commit 5ff7132313)

* siphash.h: Address lack of stdint.h for Visual Studio 2003-2008

(cherry picked from libexpat commit c74d380b8f0b5215153d840d2af9455d9c53b960)
2017-06-21 17:12:46 +02:00
Victor Stinner 0e4571a68a bpo-29591: Upgrade Modules/expat to libexpat 2.2 (#2164) (#2202)
* bpo-29591: Upgrade Modules/expat to libexpat 2.2

* bpo-29591: Restore Python changes on expat

* bpo-29591: Remove expat config of unsupported platforms

Remove the configuration (Modules/expat/*config.h) of unsupported
platforms:

* Amiga
* MacOS Classic on PPC32
* Open Watcom

* bpo-29591: Remove useless XML_HAS_SET_HASH_SALT

The XML_HAS_SET_HASH_SALT define of Modules/expat/expat.h became
useless since our local expat copy was upgrade to expat 2.1 (it's now
expat 2.2.0).

(cherry picked from commit 23ec4b57e1)
2017-06-15 02:16:35 +02:00
Victor Stinner bdd3567ccc _tkinter: Fix refleak in getint() (#2153)
PyNumber_Int() creates a new reference: need to decrement result
reference counter.
2017-06-13 11:12:01 +02:00
Stéphane Wirtel 41af942e57 bpo-30615: Fix the leak reference in Modules/_elementtree.c (#2129) 2017-06-12 15:30:48 +02:00
Serhiy Storchaka 0cc43df05e [2.7] bpo-28994: Fixed errors handling in atexit._run_exitfuncs(). (GH-2034) (#2123)
The traceback no longer displayed for SystemExit raised in a callback registered by atexit..
(cherry picked from commit 3fd54d4a7e)
2017-06-12 09:10:53 +03:00
Stéphane Wirtel 28288bebaf bpo-30614: testInitNonExistentFile() of test_bz2 leaks references (#2033)
* bpo-30614: testInitNonExistentFile() of test_bz2 leaks references

Extract the code of BZ2File_dealloc and create a new BZ2File_clear()
function. Call BZ2File_clear() in BZ2File_dealloc().

Define BZ2File_clear() as tp_clear.

Move the lock initialization before the "self->file =
PyObject_CallFunction" in BZ2File_init() and check the lock is not
created twice.

Call BZ2File_clear() in BZ2File_init() after the init of the lock

Co-Authored-By: Victor Stinner <victor.stinner@gmail.com>

* Create bz2module.c

Fix after the review of Victor Stinner
2017-06-10 14:36:57 +02:00
Mariatta 1626a479e2 [2.7] bpo-29960 _random.Random corrupted on exception in setstate(). … (#1289)
(cherry picked from commit 9616a82e78)
2017-05-27 07:19:55 -07:00
Xiang Zhang 6e1b832a6c bpo-30003: Fix handling escape characters in HZ codec (#1720) (#1556) 2017-05-23 01:04:27 +08:00
Serhiy Storchaka 955b6760cf [2.7] bpo-30363: Backport warnings in the re module. (#1577)
Running Python with the -3 option now warns about regular expression
syntax that is invalid or has different semantic in Python 3
or will change the behavior in future Python versions.
2017-05-18 12:34:40 +03:00
Serhiy Storchaka 09b52471f3 bpo-30365: Backport warnings and fix bugs in ElementTree. (#1581)
Running Python with the -3 option now emits deprecation warnings for
getchildren() and getiterator() methods of the Element class in the
xml.etree.cElementTree module and when pass the html argument to
xml.etree.ElementTree.XMLParser().

Fixed a deprecation warning about the doctype() method of the
xml.etree.ElementTree.XMLParser class.  Now it is emitted only when
define the doctype() method in the subclass of XMLParser.

Fixed a bug in the test_bug_200708_close test method.  An EchoTarget
instance was incorrectly passed to XMLParser() as the html argument and
silently ignored.

Tests no longer failed when use the -m option for running only selected
test methods. Checking warnings now is more specific, warnings are
expected only when use deprecated features.
2017-05-17 10:08:11 +03:00
Xiang Zhang 982a17e02d bpo-30242: resolve some undefined behaviours in struct (#1418) (#1588) 2017-05-15 13:17:54 +08:00
Zachary Ware f6c6d1e230 bpo-11681: Document the `-b` and `-bb` options (GH-1562) 2017-05-13 09:30:20 -05:00
Victor Stinner d2aff60719 [2.7] bpo-30283: Backport test_regrtest from master to 2.7 (#1513)
* bpo-30283: regrtest: add --testdir option

* bpo-30283: Backport _testcapi.raise_signal()

Function used by test_regrtest to simulate an interrupted unit test.

* bpo-30283: Backport test_regrtest from master
2017-05-09 13:57:20 +02:00
Xiang Zhang 4e7457b853 bpo-29990: Fix range checking in GB18030 decoder (#1509) 2017-05-09 12:18:56 +08:00
Serhiy Storchaka 5d7a18f3b6 [2.7] bpo-30243: Fixed the possibility of a crash in _json. (GH-1420) (#1471)
It was possible to get a core dump by using uninitialized
_json objects. Now __new__ methods create initialized objects.
__init__ methods are removed..
(cherry picked from commit 76a3e51a40)
2017-05-05 11:21:45 +03:00
Victor Stinner 2c27731901 bpo-30257: _bsddb: Fix newDBObject() (#1428)
Don't set cursorSetReturnsNone to DEFAULT_CURSOR_SET_RETURNS_NONE
anymore if self->myenvobj is set.

Fix a GCC warning on the strange indentation.
2017-05-03 18:04:18 +02:00
Victor Stinner 2c7085fd7b bpo-27593: Get SCM build info from git instead of hg (#1327)
Based on commit 5c4b0d063a by Ned
Deily, which is based on original patches by Brett Cannon and Steve
Dower.

Remove also the private _Py_svnversion() function and SVNVERSION
variable.

Note: Py_SubversionRevision() and Py_SubversionShortBranch() are
unchanged, they are part of the public API.
2017-05-02 16:55:50 +02:00
Serhiy Storchaka 2a1bf0633c [2.7] [3.5] bpo-30070: Fixed leaks and crashes in errors handling in the parser module. (GH-1131). (GH-1185) (#1189)
(cherry picked from commit a79f4c2195).
(cherry picked from commit 952a05e4e2)
2017-04-20 00:48:57 +03:00
Serhiy Storchaka 64aa4df850 [2.7] bpo-30061: Check if PyObject_Size()/PySequence_Size()/PyMapping_Size() (GH-1096) (GH-1180) (#1183)
raised an error.

(cherry picked from commit bf623ae884)
(cherry picked from commit 680fea4)
2017-04-19 22:34:58 +03:00
Serhiy Storchaka 5e79321742 bpo-30074: Fix compile warnings of _PySlice_Unpack and convert missed (#1154)
PySlice_GetIndicesEx in _ctypes.c.
2017-04-15 20:11:12 +03:00
Xiang Zhang 5fbdfc36f3 bpo-30068: add missing iter(self) in _io._IOBase.readlines when hint is present (#1152) 2017-04-15 13:18:22 +08:00
Mariatta b2b00e039c [2.7] bpo-29738: Fix memory leak in _get_crl_dp (GH-526) (GH-1144)
* Remove conditional on free of `dps`, since `dps` is now allocated for
all versions of OpenSSL
* Remove call to `x509_check_ca` since it was only used to cache
the `crldp` field of the certificate
CRL_DIST_POINTS_free is available in all supported versions of OpenSSL
(recent 0.9.8+) and LibreSSL.
(cherry picked from commit 2849cc34a8)
2017-04-14 18:24:22 -07:00
Serhiy Storchaka e41390aca5 bpo-27867: Expand the PySlice_GetIndicesEx macro. (#1023) (#1046)
(cherry picked from commit b879fe8)
2017-04-08 11:48:57 +03:00