diff --git a/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_api.c b/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_api.c index 4cb1c9b953..5f0fcf660c 100644 --- a/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_api.c +++ b/components/bt/host/bluedroid/bta/hf_client/bta_hf_client_api.c @@ -284,8 +284,13 @@ void BTA_HfClientSendAT(UINT16 handle, tBTA_HF_CLIENT_AT_CMD_TYPE at, UINT32 val p_buf->uint32_val2 = val2; if (str) { - strlcpy(p_buf->str, str, BTA_HF_CLIENT_NUMBER_LEN + 1); - p_buf->str[BTA_HF_CLIENT_NUMBER_LEN] = '\0'; + UINT32 str_len = strlen(str); + if (str_len > BTA_HF_CLIENT_MAX_LEN) { + APPL_TRACE_WARNING("%s, str length(%d) is more than %d, truncate it.", __FUNCTION__, str_len, BTA_HF_CLIENT_MAX_LEN); + str_len = BTA_HF_CLIENT_MAX_LEN; + } + + strlcpy(p_buf->str, str, str_len + 1); } else { p_buf->str[0] = '\0'; } diff --git a/components/bt/host/bluedroid/bta/hf_client/include/bta_hf_client_int.h b/components/bt/host/bluedroid/bta/hf_client/include/bta_hf_client_int.h index ddfc62442d..0405ab50ce 100644 --- a/components/bt/host/bluedroid/bta/hf_client/include/bta_hf_client_int.h +++ b/components/bt/host/bluedroid/bta/hf_client/include/bta_hf_client_int.h @@ -117,7 +117,7 @@ typedef struct { UINT8 uint8_val; UINT32 uint32_val1; UINT32 uint32_val2; - char str[BTA_HF_CLIENT_NUMBER_LEN + 1]; + char str[BTA_HF_CLIENT_MAX_LEN + 1]; } tBTA_HF_CLIENT_DATA_VAL; /* union of all event datatypes */ diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_hf_client_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_hf_client_api.h index e01b7a1c75..3deb9d262d 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_hf_client_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_hf_client_api.h @@ -156,6 +156,8 @@ typedef UINT8 tBTA_HF_CLIENT_IND_TYPE; typedef UINT8 tBTA_HF_CLIENT_AT_CMD_TYPE; +#define BTA_HF_CLIENT_MAX_LEN 32 + /* data associated with most non-AT events */ /* placeholder, if not needed should be removed*/ typedef struct {