* [PATCH] Fix EIR name parsing
@ 2012-01-12 18:33 Bruna Moreira
2012-01-12 19:41 ` Johan Hedberg
2012-01-12 22:27 ` Marcel Holtmann
0 siblings, 2 replies; 3+ messages in thread
From: Bruna Moreira @ 2012-01-12 18:33 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Bruna Moreira
Some vendors put a NUL byte terminator on EIR name field. If that is the
case, use -1 as string length so g_utf8_validade() can parse it
properly.
---
src/eir.c | 11 ++++++++++-
1 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/src/eir.c b/src/eir.c
index e4554e8..3826f55 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -119,6 +119,7 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
while (len < eir_len - 1) {
uint8_t field_len = eir_data[0];
+ ssize_t name_len;
/* Check for the end of EIR */
if (field_len == 0)
@@ -154,8 +155,16 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
case EIR_NAME_SHORT:
case EIR_NAME_COMPLETE:
+ /* Some vendors put a NUL byte terminator. If that is
+ * the case, use -1 as string length so
+ * g_utf8_validade() can parse it properly. */
+ if (eir_data[field_len] == '\0')
+ name_len = -1;
+ else
+ name_len = field_len - 1;
+
if (!g_utf8_validate((char *) &eir_data[2],
- field_len - 1, NULL))
+ name_len, NULL))
break;
g_free(eir->name);
--
1.7.0.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix EIR name parsing
2012-01-12 18:33 [PATCH] Fix EIR name parsing Bruna Moreira
@ 2012-01-12 19:41 ` Johan Hedberg
2012-01-12 22:27 ` Marcel Holtmann
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2012-01-12 19:41 UTC (permalink / raw)
To: Bruna Moreira; +Cc: linux-bluetooth
Hi Bruna,
On Thu, Jan 12, 2012, Bruna Moreira wrote:
> Some vendors put a NUL byte terminator on EIR name field. If that is the
> case, use -1 as string length so g_utf8_validade() can parse it
> properly.
> ---
> src/eir.c | 11 ++++++++++-
> 1 files changed, 10 insertions(+), 1 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix EIR name parsing
2012-01-12 18:33 [PATCH] Fix EIR name parsing Bruna Moreira
2012-01-12 19:41 ` Johan Hedberg
@ 2012-01-12 22:27 ` Marcel Holtmann
1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2012-01-12 22:27 UTC (permalink / raw)
To: Bruna Moreira; +Cc: linux-bluetooth
Hi Bruna,
> Some vendors put a NUL byte terminator on EIR name field. If that is the
> case, use -1 as string length so g_utf8_validade() can parse it
> properly.
> ---
> src/eir.c | 11 ++++++++++-
> 1 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/src/eir.c b/src/eir.c
> index e4554e8..3826f55 100644
> --- a/src/eir.c
> +++ b/src/eir.c
> @@ -119,6 +119,7 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
>
> while (len < eir_len - 1) {
> uint8_t field_len = eir_data[0];
> + ssize_t name_len;
>
> /* Check for the end of EIR */
> if (field_len == 0)
> @@ -154,8 +155,16 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len)
>
> case EIR_NAME_SHORT:
> case EIR_NAME_COMPLETE:
> + /* Some vendors put a NUL byte terminator. If that is
> + * the case, use -1 as string length so
> + * g_utf8_validade() can parse it properly. */
> + if (eir_data[field_len] == '\0')
> + name_len = -1;
> + else
> + name_len = field_len - 1;
> +
why do we have to do -1 here? We could just reduce the field_len by 1.
What is the point in g_utf8_validate having to figure out the length of
the data. We do already know it.
Regards
Marcel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-01-12 22:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-12 18:33 [PATCH] Fix EIR name parsing Bruna Moreira
2012-01-12 19:41 ` Johan Hedberg
2012-01-12 22:27 ` Marcel Holtmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.