Explorar o código

handle localtime errors in ctime

ctime passes the result from localtime directly to asctime. But in case
of error, localtime returns 0. This causes an error (NULL pointer
dereference) in asctime.

based on patch by Omer Anson.
Rich Felker %!s(int64=8) %!d(string=hai) anos
pai
achega
5c10c33d2a
Modificáronse 1 ficheiros con 3 adicións e 1 borrados
  1. 3 1
      src/time/ctime.c

+ 3 - 1
src/time/ctime.c

@@ -2,5 +2,7 @@
 
 char *ctime(const time_t *t)
 {
-	return asctime(localtime(t));
+	struct tm *tm = localtime(t);
+	if (!tm) return 0;
+	return asctime(tm);
 }