From 3b1acf11e98bceec44c28d9e6d665e68227d8bf2 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Tue, 22 Nov 2011 19:34:08 +0100 Subject: [PATCH 1/7] bytes() can't be used to get a representation of an object. --- Doc/library/exceptions.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/exceptions.rst b/Doc/library/exceptions.rst index 528febd031f..ca3ad3ea4c8 100644 --- a/Doc/library/exceptions.rst +++ b/Doc/library/exceptions.rst @@ -40,9 +40,9 @@ The following exceptions are used mostly as base classes for other exceptions. The base class for all built-in exceptions. It is not meant to be directly inherited by user-defined classes (for that, use :exc:`Exception`). If - :func:`bytes` or :func:`str` is called on an instance of this class, the - representation of the argument(s) to the instance are returned, or the empty - string when there were no arguments. + :func:`str` is called on an instance of this class, the representation of + the argument(s) to the instance are returned, or the empty string when + there were no arguments. .. attribute:: args From 58e8761da6d11653288b76d2dec6417000a20e74 Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Tue, 22 Nov 2011 21:51:55 +0100 Subject: [PATCH 2/7] Issue #13436: Fix a bogus error message when an AST object was passed an invalid integer value. --- Lib/test/test_ast.py | 11 +++++++++++ Misc/NEWS | 3 +++ Parser/asdl_c.py | 6 +----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 2ba3ea552d4..be9f05eb466 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -486,6 +486,17 @@ class ASTHelpers_Test(unittest.TestCase): self.assertEqual(ast.literal_eval('10 + 2j'), 10 + 2j) self.assertEqual(ast.literal_eval('1.5 - 2j'), 1.5 - 2j) + def test_bad_integer(self): + # issue13436: Bad error message with invalid numeric values + body = [ast.ImportFrom(module='time', + names=[ast.alias(name='sleep')], + level=None, + lineno=None, col_offset=None)] + mod = ast.Module(body) + with self.assertRaises(ValueError) as cm: + compile(mod, 'test', 'exec') + self.assertIn("invalid integer value: None", str(cm.exception)) + def test_main(): support.run_unittest(AST_Tests, ASTHelpers_Test) diff --git a/Misc/NEWS b/Misc/NEWS index 4e43b4546af..0b228ef14bc 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.3? Core and Builtins ----------------- +- Issue #13436: Fix a bogus error message when an AST object was passed + an invalid integer value. + - Issue #13338: Handle all enumerations in _Py_ANNOTATE_MEMORY_ORDER to allow compiling extension modules with -Wswitch-enum on gcc. Initial patch by Floris Bruynooghe. diff --git a/Parser/asdl_c.py b/Parser/asdl_c.py index 249e18ddf42..b85c07ec1b0 100755 --- a/Parser/asdl_c.py +++ b/Parser/asdl_c.py @@ -816,11 +816,7 @@ static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { int i; if (!PyLong_Check(obj)) { - PyObject *s = PyObject_Repr(obj); - if (s == NULL) return 1; - PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", - PyBytes_AS_STRING(s)); - Py_DECREF(s); + PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); return 1; } From 5e8f8104116edfcbfee2690a58391830bd9883ae Mon Sep 17 00:00:00 2001 From: Amaury Forgeot d'Arc Date: Tue, 22 Nov 2011 21:52:30 +0100 Subject: [PATCH 3/7] Issue #13436: commit regenerated Python-ast.c --- Python/Python-ast.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Python/Python-ast.c b/Python/Python-ast.c index 89c07cd602d..a276b6cf21b 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -622,11 +622,7 @@ static int obj2ast_int(PyObject* obj, int* out, PyArena* arena) { int i; if (!PyLong_Check(obj)) { - PyObject *s = PyObject_Repr(obj); - if (s == NULL) return 1; - PyErr_Format(PyExc_ValueError, "invalid integer value: %.400s", - PyBytes_AS_STRING(s)); - Py_DECREF(s); + PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj); return 1; } From 60b385e81361f43720b45b750243b39ce420a673 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 22 Nov 2011 22:01:28 +0100 Subject: [PATCH 4/7] Issue #13415: os.unsetenv() doesn't ignore errors anymore. --- Lib/test/test_os.py | 9 +++++++++ Misc/NEWS | 2 ++ Modules/posixmodule.c | 28 +++++++++++----------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index efa28ea952b..d06f08ed843 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -423,6 +423,15 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): value_str = value.decode(sys.getfilesystemencoding(), 'surrogateescape') self.assertEqual(os.environ['bytes'], value_str) + def test_unset_error(self): + if sys.platform == "win32": + # an environment variable is limited to 32,767 characters + key = 'x' * 50000 + else: + # "=" is not allowed in a variable name + key = 'key=' + self.assertRaises(OSError, os.environ.__delitem__, key) + class WalkTests(unittest.TestCase): """Tests for os.walk().""" diff --git a/Misc/NEWS b/Misc/NEWS index 4e43b4546af..7992e8b0a8a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -80,6 +80,8 @@ Core and Builtins Library ------- +- Issue #13415: os.unsetenv() doesn't ignore errors anymore. + - Issue #13322: Fix BufferedWriter.write() to ensure that BlockingIOError is raised when the wrapped raw file is non-blocking and the write would block. Previous code assumed that the raw write() would raise BlockingIOError, but diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index a27ac7111dc..728644534d4 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6106,6 +6106,12 @@ posix_putenv(PyObject *self, PyObject *args) PyBytes_FromStringAndSize does not count that */ #ifdef MS_WINDOWS len = wcslen(s1) + wcslen(s2) + 2; + if (_MAX_ENV < (len - 1)) { + PyErr_Format(PyExc_ValueError, + "the environment variable is longer than %u characters", + _MAX_ENV); + goto error; + } newstr = PyUnicode_FromUnicode(NULL, (int)len - 1); #else len = PyBytes_GET_SIZE(os1) + PyBytes_GET_SIZE(os2) + 2; @@ -6177,42 +6183,30 @@ Delete an environment variable."); static PyObject * posix_unsetenv(PyObject *self, PyObject *args) { -#ifdef MS_WINDOWS - char *s1; - - if (!PyArg_ParseTuple(args, "s:unsetenv", &s1)) - return NULL; -#else PyObject *os1; char *s1; + int err; if (!PyArg_ParseTuple(args, "O&:unsetenv", PyUnicode_FSConverter, &os1)) return NULL; s1 = PyBytes_AsString(os1); -#endif - unsetenv(s1); + err = unsetenv(s1); + if (err) + return posix_error(); /* Remove the key from posix_putenv_garbage; * this will cause it to be collected. This has to * happen after the real unsetenv() call because the * old value was still accessible until then. */ - if (PyDict_DelItem(posix_putenv_garbage, -#ifdef MS_WINDOWS - PyTuple_GET_ITEM(args, 0) -#else - os1 -#endif - )) { + if (PyDict_DelItem(posix_putenv_garbage, os1)) { /* really not much we can do; just leak */ PyErr_Clear(); } -#ifndef MS_WINDOWS Py_DECREF(os1); -#endif Py_RETURN_NONE; } #endif /* unsetenv */ From b3f82680313389bf41fd8c70620b1c336fc36ed8 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 22 Nov 2011 22:30:19 +0100 Subject: [PATCH 5/7] Issue #13436: Fix unsetenv() test on Windows --- Lib/test/test_os.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index d06f08ed843..876469b9780 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -427,10 +427,11 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol): if sys.platform == "win32": # an environment variable is limited to 32,767 characters key = 'x' * 50000 + self.assertRaises(ValueError, os.environ.__delitem__, key) else: # "=" is not allowed in a variable name key = 'key=' - self.assertRaises(OSError, os.environ.__delitem__, key) + self.assertRaises(OSError, os.environ.__delitem__, key) class WalkTests(unittest.TestCase): """Tests for os.walk().""" From c8cf4dfa2f2957c7bb7396f287fa3bcf8c9ddd24 Mon Sep 17 00:00:00 2001 From: Giampaolo Rodola' Date: Wed, 23 Nov 2011 00:03:15 +0100 Subject: [PATCH 6/7] revert cset 6a0da9b65e54 against sched.py committed by accident --- Lib/sched.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Lib/sched.py b/Lib/sched.py index 3e41198c105..6c01e6968aa 100644 --- a/Lib/sched.py +++ b/Lib/sched.py @@ -35,9 +35,6 @@ from collections import namedtuple __all__ = ["scheduler"] class Event(namedtuple('Event', 'time, priority, action, argument, kwargs')): - def __init__(self, *args, **kwargs): - super(Event, self).__init__(*args, **kwargs) - self._scheduled = False def __eq__(s, o): return (s.time, s.priority) == (o.time, o.priority) def __ne__(s, o): return (s.time, s.priority) != (o.time, o.priority) def __lt__(s, o): return (s.time, s.priority) < (o.time, o.priority) @@ -62,7 +59,6 @@ class scheduler: """ event = Event(time, priority, action, argument, kwargs) - event._scheduled = True heapq.heappush(self._queue, event) return event # The ID @@ -85,9 +81,6 @@ class scheduler: self._queue.remove(event) heapq.heapify(self._queue) - def is_scheduled(self, event): - return event._scheduled - def empty(self): """Check whether the queue is empty.""" return not self._queue @@ -129,7 +122,6 @@ class scheduler: # Verify that the event was not removed or altered # by another thread after we last looked at q[0]. if event is checked_event: - event._scheduled = False action(*argument, **kwargs) delayfunc(0) # Let other threads run else: From 116d6b98bf9c09760269db093f3251a16b6c1e81 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 23 Nov 2011 01:39:19 +0100 Subject: [PATCH 7/7] Issue #13458: Fix a memory leak in the ssl module when decoding a certificate with a subjectAltName. Patch by Robert Xiao. --- Misc/NEWS | 3 +++ Modules/_ssl.c | 1 + 2 files changed, 4 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 63508182750..f65fafe2eaf 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -83,6 +83,9 @@ Core and Builtins Library ------- +- Issue #13458: Fix a memory leak in the ssl module when decoding a + certificate with a subjectAltName. Patch by Robert Xiao. + - Issue #13415: os.unsetenv() doesn't ignore errors anymore. - Issue #13322: Fix BufferedWriter.write() to ensure that BlockingIOError is diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 84ec477aaa9..5419059e299 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -679,6 +679,7 @@ _get_peer_alt_names (X509 *certificate) { } Py_DECREF(t); } + sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); } BIO_free(biobuf); if (peer_alt_names != Py_None) {