From 326975ccad0d8c819042981e801b20e79c6c3567 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Mon, 3 Nov 2025 21:09:34 -0500 Subject: [PATCH] [core] Fix ESPTime crash (#11705) --- esphome/core/time.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/esphome/core/time.h b/esphome/core/time.h index ffcfced41..68826dabd 100644 --- a/esphome/core/time.h +++ b/esphome/core/time.h @@ -84,6 +84,9 @@ struct ESPTime { */ static ESPTime from_epoch_local(time_t epoch) { struct tm *c_tm = ::localtime(&epoch); + if (c_tm == nullptr) { + return ESPTime{}; // Return an invalid ESPTime + } return ESPTime::from_c_tm(c_tm, epoch); } /** Convert an UTC epoch timestamp to a UTC time ESPTime instance. @@ -93,6 +96,9 @@ struct ESPTime { */ static ESPTime from_epoch_utc(time_t epoch) { struct tm *c_tm = ::gmtime(&epoch); + if (c_tm == nullptr) { + return ESPTime{}; // Return an invalid ESPTime + } return ESPTime::from_c_tm(c_tm, epoch); }