]> granicus.if.org Git - python/commitdiff
Issue #8013: Fixed time.asctime segfault when OS's asctime fails
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Sun, 2 Jan 2011 20:48:22 +0000 (20:48 +0000)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Sun, 2 Jan 2011 20:48:22 +0000 (20:48 +0000)
Lib/test/test_time.py
Modules/timemodule.c

index 600d476790ad7d308b9f8d51aadf24630bb27973..c5e48df014b552f0c8a094779c08fabddf491150 100644 (file)
@@ -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)
index 89666a46ec8a7af864948e84af28a051b12521ba..e8ea66114e95a81d3f9678dcf6a27d0472a343ec 100644 (file)
@@ -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);