From 23ed275eff2ba51e441d60f5b1ebfc6b084d4285 Mon Sep 17 00:00:00 2001 From: linruihao Date: Wed, 27 Nov 2024 19:43:16 +0800 Subject: [PATCH] fix(bt/bluedroid): Allow adding empty header in OBEX and GOEP --- components/bt/host/bluedroid/stack/goep/goepc_api.c | 2 +- components/bt/host/bluedroid/stack/obex/obex_api.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/components/bt/host/bluedroid/stack/goep/goepc_api.c b/components/bt/host/bluedroid/stack/goep/goepc_api.c index 60badbaeec..350e80c9c2 100644 --- a/components/bt/host/bluedroid/stack/goep/goepc_api.c +++ b/components/bt/host/bluedroid/stack/goep/goepc_api.c @@ -359,7 +359,7 @@ UINT16 GOEPC_RequestAddHeader(UINT16 handle, UINT8 header_id, const UINT8 *data, break; } - if (data == NULL || data_len == 0) { + if ((data == NULL) ^ (data_len == 0)) { ret = GOEP_INVALID_PARAM; break; } diff --git a/components/bt/host/bluedroid/stack/obex/obex_api.c b/components/bt/host/bluedroid/stack/obex/obex_api.c index f1e1a06035..8851a0f81a 100644 --- a/components/bt/host/bluedroid/stack/obex/obex_api.c +++ b/components/bt/host/bluedroid/stack/obex/obex_api.c @@ -487,7 +487,11 @@ UINT16 OBEX_AppendHeader(BT_HDR *pkt, const UINT8 *header) *******************************************************************************/ UINT16 OBEX_AppendHeaderRaw(BT_HDR *pkt, UINT8 header_id, const UINT8 *data, UINT16 data_len) { - if (pkt == NULL || data == NULL) { + if (pkt == NULL) { + return OBEX_INVALID_PARAM; + } + + if ((data == NULL) ^ (data_len == 0)) { return OBEX_INVALID_PARAM; } @@ -533,8 +537,10 @@ UINT16 OBEX_AppendHeaderRaw(BT_HDR *pkt, UINT8 header_id, const UINT8 *data, UIN UINT16_TO_BE_FIELD(p_start, header_len); p_start+= 2; } - /* store data */ - memcpy(p_start, data, data_len); + if (data != NULL) { + /* store data */ + memcpy(p_start, data, data_len); + } pkt->len += header_len; /* point to packet len */ p_data++;