[dua-manager] avoid null dereference in CoAP response handler (#6509)

This commit changes `DuaManager::HandleDuaResponse()` to use a pointer
to `aMessage` and `aMessageInfo` (instead of reference) Note that in
case of a failure, the `Coap` module may invoke the response handler
with `nullptr` for these parameters.
This commit is contained in:
Abtin Keshavarzian
2021-04-25 21:41:34 -07:00
committed by GitHub
parent ccedef530e
commit 8a0e7b8c4e
2 changed files with 7 additions and 5 deletions
+5 -3
View File
@@ -538,7 +538,7 @@ exit:
otLogInfoDua("Sent DUA.req for DUA %s: %s", dua.ToString().AsCString(), ErrorToString(error));
}
void DuaManager::HandleDuaResponse(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, Error aResult)
void DuaManager::HandleDuaResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult)
{
OT_UNUSED_VARIABLE(aMessageInfo);
Error error;
@@ -552,10 +552,12 @@ void DuaManager::HandleDuaResponse(Coap::Message &aMessage, const Ip6::MessageIn
}
VerifyOrExit(aResult == kErrorNone, error = kErrorParse);
VerifyOrExit(aMessage.GetCode() == Coap::kCodeChanged || aMessage.GetCode() >= Coap::kCodeBadRequest,
OT_ASSERT(aMessage != nullptr);
VerifyOrExit(aMessage->GetCode() == Coap::kCodeChanged || aMessage->GetCode() >= Coap::kCodeBadRequest,
error = kErrorParse);
error = ProcessDuaResponse(aMessage);
error = ProcessDuaResponse(*aMessage);
exit:
if (error != kErrorResponseTimeout)
+2 -2
View File
@@ -201,10 +201,10 @@ private:
static void HandleDuaResponse(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, Error aResult)
{
static_cast<DuaManager *>(aContext)->HandleDuaResponse(
*static_cast<Coap::Message *>(aMessage), *static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
static_cast<Coap::Message *>(aMessage), static_cast<const Ip6::MessageInfo *>(aMessageInfo), aResult);
}
void HandleDuaResponse(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo, Error aResult);
void HandleDuaResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult);
static void HandleDuaNotification(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
{