2014-10-29 23:16:22

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 1/2] shared/hfp: Remove reduntant check

This check is not needed. Below memcmp check is sufficient
---
src/shared/hfp.c | 3 ---
1 file changed, 3 deletions(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index 22e9622..f5a812d 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -135,9 +135,6 @@ static bool match_handler_prefix(const void *a, const void *b)
const struct cmd_handler *handler = a;
const char *prefix = b;

- if (strlen(handler->prefix) != strlen(prefix))
- return false;
-
if (memcmp(handler->prefix, prefix, strlen(prefix)))
return false;

--
1.8.4



2014-10-31 19:23:09

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH 2/2] shared/hfp: Fix for invalid string copy

Hi Łukasz,

On Thursday 30 of October 2014 00:16:23 Lukasz Rymanowski wrote:
> This part of code handles case when data in ring buffer are wrapped.
> In that case str is not a string so we shall not use asprintf but
> memcpy
> ---
> src/shared/hfp.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index f5a812d..f11f02c 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -447,7 +447,15 @@ static void process_input(struct hfp_gw *hfp)
> return;
>
> *ptr = '\0';
> - count = asprintf(&ptr, "%s%s", str, str2);
> +
> + count = len2 + len;
> + ptr = malloc(count);
> + if (!ptr)
> + return;
> +
> + memcpy(ptr, str, len);
> + memcpy(ptr + len, str2, len2);
> +
> free_ptr = true;
> str = ptr;
> } else {

Patch applied, thanks.

--
BR
Szymon Janc

2014-10-30 15:09:55

by Lukasz Rymanowski

[permalink] [raw]
Subject: Re: [PATCH 1/2] shared/hfp: Remove reduntant check

Hi Marcin, Szymon,

On 30 October 2014 11:11, Marcin Kraglak <[email protected]> wrote:
> Hi Lukasz,
>
> On 30 October 2014 00:16, Lukasz Rymanowski <[email protected]> wrote:
>> This check is not needed. Below memcmp check is sufficient
>> ---
>> src/shared/hfp.c | 3 ---
>> 1 file changed, 3 deletions(-)
>>
>> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
>> index 22e9622..f5a812d 100644
>> --- a/src/shared/hfp.c
>> +++ b/src/shared/hfp.c
>> @@ -135,9 +135,6 @@ static bool match_handler_prefix(const void *a, const void *b)
>> const struct cmd_handler *handler = a;
>> const char *prefix = b;
>>
>> - if (strlen(handler->prefix) != strlen(prefix))
>> - return false;
>> -
>> if (memcmp(handler->prefix, prefix, strlen(prefix)))
>> return false;
> it is incorrect in case prefix is sub-string of handler->prefix

strcmp will do the work here.

\Lukasz
>>
>> --
>> 1.8.4
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> BR
> Marcin

2014-10-30 10:11:25

by Marcin Kraglak

[permalink] [raw]
Subject: Re: [PATCH 1/2] shared/hfp: Remove reduntant check

Hi Lukasz,

On 30 October 2014 00:16, Lukasz Rymanowski <[email protected]> wrote:
> This check is not needed. Below memcmp check is sufficient
> ---
> src/shared/hfp.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index 22e9622..f5a812d 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -135,9 +135,6 @@ static bool match_handler_prefix(const void *a, const void *b)
> const struct cmd_handler *handler = a;
> const char *prefix = b;
>
> - if (strlen(handler->prefix) != strlen(prefix))
> - return false;
> -
> if (memcmp(handler->prefix, prefix, strlen(prefix)))
> return false;
it is incorrect in case prefix is sub-string of handler->prefix
>
> --
> 1.8.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

BR
Marcin

2014-10-30 09:56:22

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH 1/2] shared/hfp: Remove reduntant check

Hi Łukasz,

On Thursday 30 of October 2014 00:16:22 Lukasz Rymanowski wrote:
> This check is not needed. Below memcmp check is sufficient
> ---
> src/shared/hfp.c | 3 ---
> 1 file changed, 3 deletions(-)
>
> diff --git a/src/shared/hfp.c b/src/shared/hfp.c
> index 22e9622..f5a812d 100644
> --- a/src/shared/hfp.c
> +++ b/src/shared/hfp.c
> @@ -135,9 +135,6 @@ static bool match_handler_prefix(const void *a, const
> void *b) const struct cmd_handler *handler = a;
> const char *prefix = b;
>
> - if (strlen(handler->prefix) != strlen(prefix))
> - return false;
> -
> if (memcmp(handler->prefix, prefix, strlen(prefix)))
> return false;

So, why not just use strcmp here instead?

--
BR
Szymon Janc

2014-10-29 23:16:23

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH 2/2] shared/hfp: Fix for invalid string copy

This part of code handles case when data in ring buffer are wrapped.
In that case str is not a string so we shall not use asprintf but
memcpy
---
src/shared/hfp.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/shared/hfp.c b/src/shared/hfp.c
index f5a812d..f11f02c 100644
--- a/src/shared/hfp.c
+++ b/src/shared/hfp.c
@@ -447,7 +447,15 @@ static void process_input(struct hfp_gw *hfp)
return;

*ptr = '\0';
- count = asprintf(&ptr, "%s%s", str, str2);
+
+ count = len2 + len;
+ ptr = malloc(count);
+ if (!ptr)
+ return;
+
+ memcpy(ptr, str, len);
+ memcpy(ptr + len, str2, len2);
+
free_ptr = true;
str = ptr;
} else {
--
1.8.4