Index: Lib/test/test_time.py =================================================================== --- Lib/test/test_time.py (Revision 87613) +++ Lib/test/test_time.py (Arbeitskopie) @@ -122,6 +122,9 @@ 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: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (Revision 87613) +++ Modules/timemodule.c (Arbeitskopie) @@ -611,18 +611,19 @@ { PyObject *tup = NULL; struct tm buf; - char *p; + char ascbuf[26]; /* e.g. "Sun Sep 16 01:03:52 1973\n\0" */ if (!PyArg_UnpackTuple(args, "asctime", 0, 1, &tup)) return NULL; if (tup == NULL) { time_t tt = time(NULL); - buf = *localtime(&tt); + (void)localtime_r(&tt, &buf); } else if (!gettmarg(tup, &buf) || !checktm(&buf)) return NULL; - p = asctime(&buf); - if (p[24] == '\n') - p[24] = '\0'; - return PyUnicode_FromString(p); + if (asctime_r(&buf, ascbuf) == NULL) { + PyErr_SetString(PyExc_ValueError, "invalid time"); + return NULL; + } + return PyUnicode_FromStringAndSize(ascbuf, 24); } PyDoc_STRVAR(asctime_doc,