From 169bf6975b06ebdd67c308c364c5f6a69bb76701 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Tue, 14 Jul 2026 10:36:38 +0800 Subject: [PATCH] fix(ble/bluedroid): reject invalid ATT error code 0x00 on client Map received error reason 0x00 to GATT_UNKNOWN_ERROR so the client does not report GATT_SUCCESS with zero-length data on malformed errors. (cherry picked from commit 1b6f9380f4fd4e20482964314e0a72fbb83a3e97) Co-authored-by: zhanghaipeng --- components/bt/host/bluedroid/stack/gatt/gatt_cl.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/stack/gatt/gatt_cl.c b/components/bt/host/bluedroid/stack/gatt/gatt_cl.c index 1fc86945659..283851bbc47 100644 --- a/components/bt/host/bluedroid/stack/gatt/gatt_cl.c +++ b/components/bt/host/bluedroid/stack/gatt/gatt_cl.c @@ -571,6 +571,11 @@ void gatt_process_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code, STREAM_TO_UINT16(handle, p); STREAM_TO_UINT8(reason, p); + /* 0x00 is not a valid ATT error code; treat as unknown error. */ + if (reason == GATT_SUCCESS) { + reason = GATT_UNKNOWN_ERROR; + } + if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY) { gatt_proc_disc_error_rsp(p_tcb, p_clcb, opcode, handle, reason); } else { @@ -579,9 +584,6 @@ void gatt_process_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code, (opcode == GATT_REQ_PREPARE_WRITE) && (p_attr) && (handle == p_attr->handle) ) { - if (reason == GATT_SUCCESS){ - reason = GATT_ERROR; - } p_clcb->status = reason; gatt_send_queue_write_cancel(p_tcb, p_clcb, GATT_PREP_WRITE_CANCEL); } else if ((p_clcb->operation == GATTC_OPTYPE_READ) &&