From 829fe1127c963924426a16bd4b0aa11a0c3f8db9 Mon Sep 17 00:00:00 2001 From: Miao-chen Chou Date: Fri, 4 Aug 2017 15:19:59 -0700 Subject: [PATCH] shared/gatt-db: Fix memory comparison error This fixes the use of memcmp where the length of comparison is longer than the memories to be compared. Since unit/test-gatt make use of gatt-db, if compiled with ASan, unit/test-gatt would fail. --- src/shared/gatt-db.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index dc7201443..f44cd1a07 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -1092,10 +1092,15 @@ static void find_by_type(void *data, void *user_data) continue; /* TODO: fix for read-callback based attributes */ - if (search_data->value && memcmp(attribute->value, - search_data->value, - search_data->value_len)) - continue; + if (search_data->value) { + if (search_data->value_len != attribute->value_len) + continue; + + if (memcmp(attribute->value, search_data->value, + search_data->value_len)) { + continue; + } + } search_data->num_of_res++; search_data->func(attribute, search_data->user_data); -- 2.47.3