From 35cfe4318ac422f5820415fe96ceb91ddcf79cf5 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 13 Sep 2024 19:42:31 -0500 Subject: [PATCH] Stop past timestamps from setting our system time RTC (#4704) * Ignore attempts to set times in the past (before our build epoch) * TRONK --- platformio.ini | 1 + src/gps/RTC.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/platformio.ini b/platformio.ini index 7613a2f43..d561aaf74 100644 --- a/platformio.ini +++ b/platformio.ini @@ -81,6 +81,7 @@ build_flags = -Wno-missing-field-initializers -DRADIOLIB_EXCLUDE_APRS -DRADIOLIB_EXCLUDE_LORAWAN -DMESHTASTIC_EXCLUDE_DROPZONE=1 + -DBUILD_EPOCH=$UNIX_TIME ;-D OLED_PL monitor_speed = 115200 diff --git a/src/gps/RTC.cpp b/src/gps/RTC.cpp index c056bb9e4..42a98f568 100644 --- a/src/gps/RTC.cpp +++ b/src/gps/RTC.cpp @@ -109,6 +109,12 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpdate) static uint32_t lastSetMsec = 0; uint32_t now = millis(); uint32_t printableEpoch = tv->tv_sec; // Print lib only supports 32 bit but time_t can be 64 bit on some platforms +#ifdef BUILD_EPOCH + if (tv->tv_sec < BUILD_EPOCH) { + LOG_WARN("Ignoring time (%ld) before build epoch (%ld)!\n", printableEpoch, BUILD_EPOCH); + return false; + } +#endif bool shouldSet; if (forceUpdate) {