From 8f013f79801ae1bfb6daa37dbe306fe36a33e678 Mon Sep 17 00:00:00 2001 From: Hui Peng <phui@google.com> Date: Thu, 19 Jan 2023 19:35:26 +0000 Subject: [PATCH] Fix an OOB bug in gatt_dbg_op_name Bug: 260079141 Test: manual Ignore-AOSP-First: security Change-Id: If8be70e134fdf1f6edb43d0360c524fffed6045b --- system/stack/gatt/gatt_utils.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/system/stack/gatt/gatt_utils.cc b/system/stack/gatt/gatt_utils.cc index 1311500d65e..25f4e133427 100644 --- a/system/stack/gatt/gatt_utils.cc +++ b/system/stack/gatt/gatt_utils.cc @@ -1630,10 +1630,12 @@ uint8_t* gatt_dbg_op_name(uint8_t op_code) { pseduo_op_code_idx = 0x15; /* just an index to op_code_name */ } - if (pseduo_op_code_idx <= GATT_OP_CODE_MAX) + #define ARR_SIZE(a) (sizeof(a)/sizeof(a[0])) + if (pseduo_op_code_idx < ARR_SIZE(op_code_name)) return (uint8_t*)op_code_name[pseduo_op_code_idx]; else return (uint8_t*)"Op Code Exceed Max"; + #undef ARR_SIZE } /** Remove the application interface for the specified background device */ -- GitLab