[Python-checkins] [3.7] bpo-35373: Fix PyInit_timezone() error handling (GH-10864)
Victor Stinner
webhook-mailer at python.org
Mon Dec 3 18:09:07 EST 2018
https://github.com/python/cpython/commit/5eb78c75128187a36d8e983027632fa51cc2ff4d
commit: 5eb78c75128187a36d8e983027632fa51cc2ff4d
branch: 3.7
author: Victor Stinner <vstinner at redhat.com>
committer: GitHub <noreply at github.com>
date: 2018年12月04日T00:09:02+01:00
summary:
[3.7] bpo-35373: Fix PyInit_timezone() error handling (GH-10864)
* bpo-35373: Fix PyInit_timezone() error handling
PyInit_timezone() now returns -1 at exit if an exception is raised.
Check also explicitly PyUnicode_DecodeLocale() and Py_BuildValue()
errors.
* bpo-35373: Fix PyInit_time() error handling (GH-10865)
* PyInit_time() now returns NULL if an exception is raised.
* Rename PyInit_timezone() to init_timezone(). "PyInit_" prefix is
a special prefix for function initializing a module.
init_timezone() doesn't initialize a module and the function is not
exported.
(cherry picked from commit 3bb150d8148e3cc08418077a58f43e064b9fde61)
files:
M Modules/timemodule.c
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 6cf9e7c641e3..13a174a4ea87 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -994,7 +994,7 @@ of the timezone or altzone attributes on the time module.");
#endif /* HAVE_MKTIME */
#ifdef HAVE_WORKING_TZSET
-static int PyInit_timezone(PyObject *module);
+static int init_timezone(PyObject *module);
static PyObject *
time_tzset(PyObject *self, PyObject *unused)
@@ -1009,7 +1009,7 @@ time_tzset(PyObject *self, PyObject *unused)
tzset();
/* Reset timezone, altzone, daylight and tzname */
- if (PyInit_timezone(m) < 0) {
+ if (init_timezone(m) < 0) {
return NULL;
}
Py_DECREF(m);
@@ -1524,7 +1524,7 @@ get_gmtoff(time_t t, struct tm *p)
#endif /* !defined(HAVE_TZNAME) || defined(__GLIBC__) || defined(__CYGWIN__) */
static int
-PyInit_timezone(PyObject *m)
+init_timezone(PyObject *m)
{
assert(!PyErr_Occurred());
@@ -1555,8 +1555,19 @@ PyInit_timezone(PyObject *m)
#endif
PyModule_AddIntConstant(m, "daylight", daylight);
otz0 = PyUnicode_DecodeLocale(tzname[0], "surrogateescape");
+ if (otz0 == NULL) {
+ return -1;
+ }
otz1 = PyUnicode_DecodeLocale(tzname[1], "surrogateescape");
- PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1));
+ if (otz1 == NULL) {
+ Py_DECREF(otz0);
+ return -1;
+ }
+ PyObject *tzname_obj = Py_BuildValue("(NN)", otz0, otz1);
+ if (tzname_obj == NULL) {
+ return -1;
+ }
+ PyModule_AddObject(m, "tzname", tzname_obj);
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
{
#define YEAR ((time_t)((365 * 24 + 6) * 3600))
@@ -1615,6 +1626,10 @@ PyInit_timezone(PyObject *m)
Py_BuildValue("(zz)", _tzname[0], _tzname[1]));
#endif /* __CYGWIN__ */
#endif /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
+
+ if (PyErr_Occurred()) {
+ return -1;
+ }
return 0;
}
@@ -1716,7 +1731,7 @@ PyInit_time(void)
return NULL;
/* Set, or reset, module variables like time.timezone */
- if (PyInit_timezone(m) < 0) {
+ if (init_timezone(m) < 0) {
return NULL;
}
@@ -1761,6 +1776,10 @@ PyInit_time(void)
PyModule_AddIntConstant(m, "_STRUCT_TM_ITEMS", 11);
PyModule_AddObject(m, "struct_time", (PyObject*) &StructTimeType);
initialized = 1;
+
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
return m;
}
More information about the Python-checkins
mailing list