From: Alexander Belopolsky Date: Sun, 2 Jan 2011 20:48:22 +0000 (+0000) Subject: Issue #8013: Fixed time.asctime segfault when OS's asctime fails X-Git-Tag: v3.2rc1~248 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e2dc0822941fd81e9db017f85a8475a26c00f952;p=python Issue #8013: Fixed time.asctime segfault when OS's asctime fails --- diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 600d476790..c5e48df014 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -122,6 +122,9 @@ class TimeTestCase(unittest.TestCase): def test_asctime(self): time.asctime(time.gmtime(self.t)) self.assertRaises(TypeError, time.asctime, 0) + self.assertRaises(TypeError, time.asctime, ()) + self.assertRaises(ValueError, time.asctime, + (12345, 1, 0, 0, 0, 0, 0, 0, 0)) def test_asctime_bounding_check(self): self._bounds_checking(time.asctime) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 89666a46ec..e8ea66114e 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -620,6 +620,10 @@ time_asctime(PyObject *self, PyObject *args) } else if (!gettmarg(tup, &buf) || !checktm(&buf)) return NULL; p = asctime(&buf); + if (p == NULL) { + PyErr_SetString(PyExc_ValueError, "invalid time"); + return NULL; + } if (p[24] == '\n') p[24] = '\0'; return PyUnicode_FromString(p);