From 6501048c0dd5fa5446705631485a39661e250fd7 Mon Sep 17 00:00:00 2001 From: Fesseha Date: Fri, 5 Apr 2024 13:54:20 +0200 Subject: [PATCH] - improved time zone name changing check - improved time zone name copying buffer size comparison --- .../time-synchronization-server.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp index 3d21a0795f0bb2..ecd2d1744fba5d 100644 --- a/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp +++ b/src/app/clusters/time-synchronization-server/time-synchronization-server.cpp @@ -551,9 +551,9 @@ CHIP_ERROR TimeSynchronizationServer::SetTimeZone(const DataModel::DecodableList if (lastTzState != TimeState::kInvalid) { - const auto & tzStore = GetTimeZone()[0]; - lastTz.offset = tzStore.timeZone.offset; - if (tzStore.timeZone.name.HasValue()) + const TimeSyncDataProvider::TimeZoneStore & tzStore = GetTimeZone()[0]; + lastTz.offset = tzStore.timeZone.offset; + if (tzStore.timeZone.name.HasValue() && sizeof(name) >= sizeof(tzStore.name)) { lastTz.name.SetValue(CharSpan(name)); memcpy(name, tzStore.name, sizeof(tzStore.name)); @@ -623,7 +623,8 @@ CHIP_ERROR TimeSynchronizationServer::SetTimeZone(const DataModel::DecodableList { emit = true; } - if ((tz.name.HasValue() && lastTz.name.HasValue()) && !(tz.name.Value().data_equal(lastTz.name.Value()))) + if (tz.name.HasValue() != lastTz.name.HasValue() || + ((tz.name.HasValue() && lastTz.name.HasValue()) && !(tz.name.Value().data_equal(lastTz.name.Value())))) { emit = true; }