summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2023-05-10 12:10:14 -0700
committerPaul Smith <psmith@gnu.org>2023-05-14 18:26:35 -0400
commit032f784601219474ac2a31d61caa071665451933 (patch)
treea6edf0663be3902e025697a9a0ea73bcadbff4dd
parent78e6a89b192c1f5ce5f06a55216164a1063da23f (diff)
downloadmake-git-032f784601219474ac2a31d61caa071665451933.tar.gz
make -p buffer overrun fix with outlandish current time
* src/main.c (safer_ctime): New function. (print_data_base): Use it.
-rw-r--r--src/main.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index fdd4e9d4..d22d170a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -3720,6 +3720,18 @@ print_version (void)
printed_version = 1;
}
+/* Like ctime, except do not have undefined behavior with timestamps
+ out of ctime range. */
+static char const *
+safer_ctime (time_t *t)
+{
+ struct tm *tm = localtime (t);
+ if (tm && -999 - 1900 <= tm->tm_year && tm->tm_year <= 9999 - 1900)
+ return ctime (t);
+ else
+ return "(time out of range)\n";
+}
+
static time_t
time_now (void)
{
@@ -3758,7 +3770,7 @@ print_data_base (void)
print_version ();
- printf (_("\n# Make data base, printed on %s"), ctime (&when));
+ printf (_("\n# Make data base, printed on %s"), safer_ctime (&when));
print_variable_data_base ();
print_dir_data_base ();
@@ -3768,7 +3780,7 @@ print_data_base (void)
strcache_print_stats ("#");
when = time_now ();
- printf (_("\n# Finished Make data base on %s\n"), ctime (&when));
+ printf (_("\n# Finished Make data base on %s\n"), safer_ctime (&when));
}
static void