2017-08-04 21:25:52

by Miao-chen Chou

[permalink] [raw]
Subject: [PATCH] shared/gatt-db: Fix memory comparison error

From: Miao-chen Chou <[email protected]>

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 8ef6f3bca..b7bbaed93 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1013,10 +1013,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.14.0.rc1.383.gd1ce394fe2-goog



2017-08-08 11:20:57

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] shared/gatt-db: Fix memory comparison error

Hi Miao,

On Tue, Aug 8, 2017 at 12:17 AM, Miao-chen Chou <[email protected]> wrote:
> Hi,
>
> Please see the full description of the issue at
> https://bugs.chromium.org/p/chromium/issues/detail?id=748216#c4.
>
> Thanks,
> Miao
>
> On Fri, Aug 4, 2017 at 3:19 PM, <[email protected]> wrote:
>> From: Miao-chen Chou <[email protected]>
>>
>> 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 8ef6f3bca..2dd73b997 100644
>> --- a/src/shared/gatt-db.c
>> +++ b/src/shared/gatt-db.c
>> @@ -1013,10 +1013,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.14.0.rc1.383.gd1ce394fe2-goog
>>

Applied, thanks.

--
Luiz Augusto von Dentz

2017-08-07 21:17:44

by Miao-chen Chou

[permalink] [raw]
Subject: Re: [PATCH] shared/gatt-db: Fix memory comparison error

Hi,

Please see the full description of the issue at
https://bugs.chromium.org/p/chromium/issues/detail?id=748216#c4.

Thanks,
Miao

On Fri, Aug 4, 2017 at 3:19 PM, <[email protected]> wrote:
> From: Miao-chen Chou <[email protected]>
>
> 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 8ef6f3bca..2dd73b997 100644
> --- a/src/shared/gatt-db.c
> +++ b/src/shared/gatt-db.c
> @@ -1013,10 +1013,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.14.0.rc1.383.gd1ce394fe2-goog
>

2017-08-04 22:19:59

by Miao-chen Chou

[permalink] [raw]
Subject: [PATCH] shared/gatt-db: Fix memory comparison error

From: Miao-chen Chou <[email protected]>

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 8ef6f3bca..2dd73b997 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -1013,10 +1013,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.14.0.rc1.383.gd1ce394fe2-goog