From 2db44eba7013c2b7a104cf52e1a3f4e4cf8e03be Mon Sep 17 00:00:00 2001 From: Kamil Kasperczyk <66371704+kkasperczyk-no@users.noreply.github.com> Date: Tue, 14 May 2024 14:58:02 +0200 Subject: [PATCH] [openthread] Fixed potential usage fault (#33434) Pointer to the ThreadDiagnosticsDelegate is used without a null check. It leads to the usage fault, if ThreadNetworkDiagnostics cluster is disabled and pointer is set to nullptr. --- ...nericThreadStackManagerImpl_OpenThread.hpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index 1b7f1c52deeaa9..2149a17b667fe6 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -227,18 +227,22 @@ void GenericThreadStackManagerImpl_OpenThread::_OnPlatformEvent(const ThreadDiagnosticsDelegate * delegate = GetDiagnosticDataProvider().GetThreadDiagnosticsDelegate(); - if (mIsAttached) + if (delegate) { - delegate->OnConnectionStatusChanged(app::Clusters::ThreadNetworkDiagnostics::ConnectionStatusEnum::kConnected); - } - else - { - delegate->OnConnectionStatusChanged(app::Clusters::ThreadNetworkDiagnostics::ConnectionStatusEnum::kNotConnected); + if (mIsAttached) + { + delegate->OnConnectionStatusChanged(app::Clusters::ThreadNetworkDiagnostics::ConnectionStatusEnum::kConnected); + } + else + { + delegate->OnConnectionStatusChanged( + app::Clusters::ThreadNetworkDiagnostics::ConnectionStatusEnum::kNotConnected); - GeneralFaults current; - current.add(to_underlying(chip::app::Clusters::ThreadNetworkDiagnostics::NetworkFaultEnum::kLinkDown)); - delegate->OnNetworkFaultChanged(mNetworkFaults, current); - mNetworkFaults = current; + GeneralFaults current; + current.add(to_underlying(chip::app::Clusters::ThreadNetworkDiagnostics::NetworkFaultEnum::kLinkDown)); + delegate->OnNetworkFaultChanged(mNetworkFaults, current); + mNetworkFaults = current; + } } }