From 052f162aa03489d359a4719195b4acc00427a2d2 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 c28cb86edf0085..12f9af57a44342 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; + } } }