]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don’t crash if localtime returns null pointer in localtime_r replacement
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 22 Sep 2019 17:46:42 +0000 (19:46 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 22 Sep 2019 17:54:51 +0000 (19:54 +0200)
This seems to happen in some unknown Windows environment, see #450.

Fixes #450.

(cherry picked from commit 8c4ffbab96a8f4bebc27b39ad3a235a5d8baeab3)

src/hashutil.cpp
src/util.cpp

index d3a9974071c3d9a794f0b8a6f6f1ea746b11c886..93317522cdebde979bc23a3c497f14f7a0157cc3 100644 (file)
@@ -88,13 +88,16 @@ hash_source_code_string(const Config& config,
   hash_string_buffer(hash, str, len);
 
   if (result & HASH_SOURCE_CODE_FOUND_DATE) {
+    cc_log("Found __DATE__ in %s", path);
+
     // Make sure that the hash sum changes if the (potential) expansion of
     // __DATE__ changes.
     time_t t = time(NULL);
     struct tm now;
-    localtime_r(&t, &now);
-    cc_log("Found __DATE__ in %s", path);
     hash_delimiter(hash, "date");
+    if (!localtime_r(&t, &now)) {
+      return HASH_SOURCE_CODE_ERROR;
+    }
     hash_int(hash, now.tm_year);
     hash_int(hash, now.tm_mon);
     hash_int(hash, now.tm_mday);
index 978cd227e3c9900a1d65051e1a729775f85fa449..7948938bab5e4daac47ed44259b30e3faccaa2c5 100644 (file)
@@ -1134,8 +1134,13 @@ struct tm*
 localtime_r(const time_t* timep, struct tm* result)
 {
   struct tm* tm = localtime(timep);
-  *result = *tm;
-  return result;
+  if (tm) {
+    *result = *tm;
+    return result;
+  } else {
+    memset(result, 0, sizeof(*result));
+    return NULL;
+  }
 }
 #endif