From 7de77117b08d952084a014d9dd71bd570ff6057f Mon Sep 17 00:00:00 2001 From: yexiaokang Date: Thu, 26 Jun 2025 17:19:09 +0800 Subject: [PATCH] fix use after free iface Signed-off-by: yexiaokang --- nstackx_ctrl/core/coap_discover/coap_discover.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nstackx_ctrl/core/coap_discover/coap_discover.c b/nstackx_ctrl/core/coap_discover/coap_discover.c index b221ddd..3cdfd89 100644 --- a/nstackx_ctrl/core/coap_discover/coap_discover.c +++ b/nstackx_ctrl/core/coap_discover/coap_discover.c @@ -345,6 +345,11 @@ static int32_t HndPostServiceDiscoverEx(coap_session_t *session, const coap_pdu_ goto L_ERR; } + if (coapCtx->freeCtxLater == NSTACKX_TRUE) { + DFINDER_LOGE(TAG, "coapCtx is will free"); + goto L_ERR; + } + if (strcpy_s(deviceInfo->networkName, sizeof(deviceInfo->networkName), GetLocalIfaceName(coapCtx->iface)) != EOK) { DFINDER_LOGE(TAG, "copy local network name %s fail", GetLocalIfaceName(coapCtx->iface)); @@ -640,6 +645,11 @@ static void HndPostServiceMsg(coap_resource_t *resource, coap_session_t *session static int32_t CoapPostServiceDiscoverEx(CoapCtxType *ctx) { + if (ctx->freeCtxLater == NSTACKX_TRUE) { + DFINDER_LOGE(TAG, "ctx is will free"); + return NSTACKX_EFAILED; + } + char broadcastIp[NSTACKX_MAX_IP_STRING_LEN] = {0}; if (GetBroadcastIp(ctx->iface, broadcastIp, sizeof(broadcastIp)) != NSTACKX_EOK) { DFINDER_LOGE(TAG, "get broadcast ip failed");