Issue #8013: Fixed time.asctime segfault when OS's asctime fails
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 89666a4..e8ea661 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -620,6 +620,10 @@
     } 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);