From b0984aff7a64ab8c0d745fdde741ded77e95ffa7 Mon Sep 17 00:00:00 2001 From: Yang Sun Date: Mon, 4 Nov 2024 23:05:55 +0800 Subject: [PATCH] [trel] fix crash (#10894) Started from #10872, platform trel stays un-initialized if no TREL URL is passed in. `otPlatTrelEnable` asserted for `sInitialized`, and caused crashes when `otPlatTrelEnable()` is called. This commit changes the assertions to VerifyOrExit() to allow otPlatTrelEnable calls when TREL is not initialized. --- src/posix/platform/trel.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/posix/platform/trel.cpp b/src/posix/platform/trel.cpp index 82af858da..95a889abf 100644 --- a/src/posix/platform/trel.cpp +++ b/src/posix/platform/trel.cpp @@ -474,9 +474,7 @@ void otPlatTrelEnable(otInstance *aInstance, uint16_t *aUdpPort) VerifyOrExit(!IsSystemDryRun()); - assert(sInitialized); - - VerifyOrExit(!sEnabled); + VerifyOrExit(sInitialized && !sEnabled); PrepareSocket(*aUdpPort); trelDnssdStartBrowse(); @@ -493,8 +491,7 @@ void otPlatTrelDisable(otInstance *aInstance) VerifyOrExit(!IsSystemDryRun()); - assert(sInitialized); - VerifyOrExit(sEnabled); + VerifyOrExit(sInitialized && sEnabled); close(sSocket); sSocket = -1; @@ -541,6 +538,8 @@ void otPlatTrelRegisterService(otInstance *aInstance, uint16_t aPort, const uint OT_UNUSED_VARIABLE(aInstance); VerifyOrExit(!IsSystemDryRun()); + VerifyOrExit(sEnabled); + trelDnssdRegisterService(aPort, aTxtData, aTxtLength); exit: