]> granicus.if.org Git - python/commitdiff
Merged revisions 87663 via svnmerge from
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Sun, 2 Jan 2011 23:26:12 +0000 (23:26 +0000)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Sun, 2 Jan 2011 23:26:12 +0000 (23:26 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/release27-maint

................
  r87663 | alexander.belopolsky | 2011-01-02 18:23:54 -0500 (Sun, 02 Jan 2011) | 13 lines

  Merged revisions 87648,87656 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/branches/py3k

  ........
    r87648 | alexander.belopolsky | 2011-01-02 15:48:22 -0500 (Sun, 02 Jan 2011) | 1 line

    Issue #8013: Fixed time.asctime segfault when OS's asctime fails
  ........
    r87656 | alexander.belopolsky | 2011-01-02 17:16:10 -0500 (Sun, 02 Jan 2011) | 1 line

    Issue #8013: Fixed test
  ........
................

Lib/test/test_time.py
Modules/timemodule.c

index b5155b4f999784583ea20b30569c85e993826c57..d173ae1ca243606d02929239926c83e7d91c9362 100644 (file)
@@ -119,6 +119,16 @@ 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, ())
+        # XXX: Posix compiant asctime should refuse to convert
+        # year > 9999, but Linux implementation does not.
+        # self.assertRaises(ValueError, time.asctime,
+        #                  (12345, 1, 0, 0, 0, 0, 0, 0, 0))
+        # XXX: For now, just make sure we don't have a crash:
+        try:
+            time.asctime((12345, 1, 0, 0, 0, 0, 0, 0, 0))
+        except ValueError:
+            pass
 
     def test_tzset(self):
         if not hasattr(time, "tzset"):
index d6d4160da380b299dcea2d7500c41b80316b9d6c..a59d3f0600a1075efc5664cffa7ae6b94cebd64b 100644 (file)
@@ -546,6 +546,10 @@ time_asctime(PyObject *self, PyObject *args)
     } else if (!gettmarg(tup, &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 PyString_FromString(p);