diff options
author | Yang Sun <sunytt@google.com> | 2024-02-29 13:25:00 +0800 |
---|---|---|
committer | Yang Sun <sunytt@google.com> | 2024-02-29 14:49:27 +0800 |
commit | 0a1a82391d8cb8aca62973082641edf75e5025eb (patch) | |
tree | 2d7c74e749a36376e7b99efa1175b0a4d36ef3e3 | |
parent | d41c1ff7e17f83eb6eae04268392d1069dc88d7d (diff) | |
download | ot-br-posix-0a1a82391d8cb8aca62973082641edf75e5025eb.tar.gz |
Check for GetOtInstance() and mCallback nullability
Follow-up for aosp/2926231
Bug:327370365
Test: fuzzer test https://paste.googleplex.com/5991001975422976
atest ThreadNetworkIntegrationTests:android.net.thread.BorderRoutingTest
Change-Id: Ie924e210df6487ce6d585d9947c7a2d10f0448ce
-rw-r--r-- | src/android/otdaemon_server.cpp | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/android/otdaemon_server.cpp b/src/android/otdaemon_server.cpp index 005400b6..ce985bb5 100644 --- a/src/android/otdaemon_server.cpp +++ b/src/android/otdaemon_server.cpp @@ -153,7 +153,14 @@ void OtDaemonServer::StateCallback(otChangedFlags aFlags) } if (aFlags & OT_CHANGED_THREAD_BACKBONE_ROUTER_STATE) { - mCallback->onBackboneRouterStateChanged(GetBackboneRouterState()); + if (mCallback == nullptr) + { + otbrLogWarning("Ignoring OT backbone router state changes: callback is not set"); + } + else + { + mCallback->onBackboneRouterStateChanged(GetBackboneRouterState()); + } } } @@ -264,17 +271,14 @@ exit: BackboneRouterState OtDaemonServer::GetBackboneRouterState() { BackboneRouterState state; - otBackboneRouterState bbrState = otBackboneRouterGetState(GetOtInstance()); + otBackboneRouterState bbrState; otBackboneRouterMulticastListenerInfo info; otBackboneRouterMulticastListenerIterator iter = OT_BACKBONE_ROUTER_MULTICAST_LISTENER_ITERATOR_INIT; state.listeningAddresses = std::vector<std::string>(); - if (mCallback == nullptr) - { - otbrLogWarning("OT daemon callback is not set"); - return state; - } + VerifyOrExit(GetOtInstance() != nullptr, otbrLogWarning("Can't get bbr state: OT is not initialized")); + bbrState = otBackboneRouterGetState(GetOtInstance()); switch (bbrState) { case OT_BACKBONE_ROUTER_STATE_DISABLED: @@ -295,6 +299,7 @@ BackboneRouterState OtDaemonServer::GetBackboneRouterState() state.listeningAddresses.push_back(string); } +exit: return state; } @@ -310,7 +315,15 @@ void OtDaemonServer::HandleBackboneMulticastListenerEvent(void otbrLogDebug("Multicast forwarding address changed, %s is %s", addressString, (aEvent == OT_BACKBONE_ROUTER_MULTICAST_LISTENER_ADDED) ? "added" : "removed"); + if (thisServer->mCallback == nullptr) + { + otbrLogWarning("Ignoring OT multicast listener event: callback is not set"); + ExitNow(); + } thisServer->mCallback->onBackboneRouterStateChanged(thisServer->GetBackboneRouterState()); + +exit: + return; } otInstance *OtDaemonServer::GetOtInstance() @@ -534,7 +547,7 @@ Status OtDaemonServer::join(const std::vector<uint8_t> &aActiveOpD message = "Thread is disabling"); VerifyOrExit(mThreadEnabled == IOtDaemon::OT_STATE_ENABLED, - error = static_cast<int>(IOtDaemon::ErrorCode::OT_ERROR_THREAD_DISABLED), + error = static_cast<int>(IOtDaemon::ErrorCode::OT_ERROR_THREAD_DISABLED), message = "Thread is disabled"); otbrLogInfo("Start joining..."); @@ -658,7 +671,7 @@ Status OtDaemonServer::scheduleMigration(const std::vector<uint8_t> message = "Thread is disabling"); VerifyOrExit(mThreadEnabled == IOtDaemon::OT_STATE_ENABLED, - error = static_cast<int>(IOtDaemon::ErrorCode::OT_ERROR_THREAD_DISABLED), + error = static_cast<int>(IOtDaemon::ErrorCode::OT_ERROR_THREAD_DISABLED), message = "Thread is disabled"); if (GetOtInstance() == nullptr) |