Index: Lib/test/test_time.py =================================================================== --- Lib/test/test_time.py (revision 78430) +++ Lib/test/test_time.py (working copy) @@ -114,6 +114,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_tzset(self): if not hasattr(time, "tzset"): Index: Modules/timemodule.c =================================================================== --- Modules/timemodule.c (revision 78430) +++ Modules/timemodule.c (working copy) @@ -557,18 +557,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)) return NULL; - p = asctime(&buf); - if (p[24] == '\n') - p[24] = '\0'; - return PyString_FromString(p); + if (asctime_r(&buf, ascbuf) == NULL) { + PyErr_SetString(PyExc_ValueError, "invalid time"); + return NULL; + } + return PyString_FromStringAndSize(ascbuf, 24); } PyDoc_STRVAR(asctime_doc,