* [PATCH 1/2] shared/hfp: Remove reduntant check
@ 2014-10-29 23:16 Lukasz Rymanowski
2014-10-29 23:16 ` [PATCH 2/2] shared/hfp: Fix for invalid string copy Lukasz Rymanowski
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Lukasz Rymanowski @ 2014-10-29 23:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Lukasz Rymanowski
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
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] shared/hfp: Fix for invalid string copy
2014-10-29 23:16 [PATCH 1/2] shared/hfp: Remove reduntant check Lukasz Rymanowski
@ 2014-10-29 23:16 ` Lukasz Rymanowski
2014-10-31 19:23 ` Szymon Janc
2014-10-30 9:56 ` [PATCH 1/2] shared/hfp: Remove reduntant check Szymon Janc
2014-10-30 10:11 ` Marcin Kraglak
2 siblings, 1 reply; 6+ messages in thread
From: Lukasz Rymanowski @ 2014-10-29 23:16 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Lukasz Rymanowski
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
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] shared/hfp: Fix for invalid string copy
2014-10-29 23:16 ` [PATCH 2/2] shared/hfp: Fix for invalid string copy Lukasz Rymanowski
@ 2014-10-31 19:23 ` Szymon Janc
0 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2014-10-31 19:23 UTC (permalink / raw)
To: Lukasz Rymanowski; +Cc: linux-bluetooth
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] shared/hfp: Remove reduntant check
2014-10-29 23:16 [PATCH 1/2] shared/hfp: Remove reduntant check Lukasz Rymanowski
2014-10-29 23:16 ` [PATCH 2/2] shared/hfp: Fix for invalid string copy Lukasz Rymanowski
@ 2014-10-30 9:56 ` Szymon Janc
2014-10-30 10:11 ` Marcin Kraglak
2 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2014-10-30 9:56 UTC (permalink / raw)
To: Lukasz Rymanowski; +Cc: linux-bluetooth
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] shared/hfp: Remove reduntant check
2014-10-29 23:16 [PATCH 1/2] shared/hfp: Remove reduntant check Lukasz Rymanowski
2014-10-29 23:16 ` [PATCH 2/2] shared/hfp: Fix for invalid string copy Lukasz Rymanowski
2014-10-30 9:56 ` [PATCH 1/2] shared/hfp: Remove reduntant check Szymon Janc
@ 2014-10-30 10:11 ` Marcin Kraglak
2014-10-30 15:09 ` Lukasz Rymanowski
2 siblings, 1 reply; 6+ messages in thread
From: Marcin Kraglak @ 2014-10-30 10:11 UTC (permalink / raw)
To: Lukasz Rymanowski; +Cc: linux-bluetooth@vger.kernel.org development
Hi Lukasz,
On 30 October 2014 00:16, Lukasz Rymanowski <lukasz.rymanowski@tieto.com> 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 majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
BR
Marcin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] shared/hfp: Remove reduntant check
2014-10-30 10:11 ` Marcin Kraglak
@ 2014-10-30 15:09 ` Lukasz Rymanowski
0 siblings, 0 replies; 6+ messages in thread
From: Lukasz Rymanowski @ 2014-10-30 15:09 UTC (permalink / raw)
To: Marcin Kraglak; +Cc: linux-bluetooth@vger.kernel.org development
Hi Marcin, Szymon,
On 30 October 2014 11:11, Marcin Kraglak <marcin.kraglak@tieto.com> wrote:
> Hi Lukasz,
>
> On 30 October 2014 00:16, Lukasz Rymanowski <lukasz.rymanowski@tieto.com> 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 majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
> BR
> Marcin
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-10-31 19:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-29 23:16 [PATCH 1/2] shared/hfp: Remove reduntant check Lukasz Rymanowski
2014-10-29 23:16 ` [PATCH 2/2] shared/hfp: Fix for invalid string copy Lukasz Rymanowski
2014-10-31 19:23 ` Szymon Janc
2014-10-30 9:56 ` [PATCH 1/2] shared/hfp: Remove reduntant check Szymon Janc
2014-10-30 10:11 ` Marcin Kraglak
2014-10-30 15:09 ` Lukasz Rymanowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox