2004-02-23 03:18:41

by James Courtier-Dutton

[permalink] [raw]
Subject: [Bluez-devel] [PATCH] Fix some bugs in hcidump.

Attached is a patch to apply to bluez-hcidump-1.5/parser/sdp.c

It fixes some of the printout.

Cheers
James


Attachments:
sdp.c.diff (1.41 kB)

2004-02-23 17:39:17

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] [PATCH] Fix some bugs in hcidump.

Hi James,

> I have also added some extra checks so that the while loops will not go
> mad if there is a badly formed packet. I.E. n,n1,n2 get given bad values.

patch is applied with some cosmetical changes.

Regards

Marcel




-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2004-02-23 15:04:51

by James Courtier-Dutton

[permalink] [raw]
Subject: Re: [Bluez-devel] [PATCH] Fix some bugs in hcidump.

Marcel Holtmann wrote:
>>Do you want me to resubmit the patch as a "cvs -u diff" ?
>
>
> yes. And please remove the initial assignment of len.
>
> Regards
>
> Marcel
>
>
See attached patch.
I have also added some extra checks so that the while loops will not go
mad if there is a badly formed packet. I.E. n,n1,n2 get given bad values.

Cheers
James



Attachments:
hcidump-fix-sdp.patch (2.09 kB)

2004-02-23 14:04:45

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] [PATCH] Fix some bugs in hcidump.

Hi James,

> Each call to parse_de_hdr and print_uuid changes the value of frm->len.
> So, each time round the while loop (len - frm->len) becomes larger.
>
> The n1 value is set by the previous line
> "if (parse_de_hdr(frm, &n1) == SDP_DE_SEQ) {"
>
> This means we have n1 bytes of data we wish to parse inside the while loop.
> So, we want to start the while loop with (len - frm->len) == 0
> Each time round the loop (len - frm->len) will increase( due to calls to
> parse_de_hdr and print_uuid) , and the loop will exit when (len -
> frm->len) >= n1, which is what we want.
>
> If we fail to set "len = frm->len;" just before the while loop, the
> previous line
> "if (parse_de_hdr(frm, &n1) == SDP_DE_SEQ) {"
> changes frm->len, so the "int len = frm->len;" at the beginning of the
> function is no longer correct.
> I.E. len != frm->len after the "if (parse_de_hdr(frm, &n1) ==
> SDP_DE_SEQ) {" statement.
>
> I hope this explanation is clear.
>
> Do you want me to resubmit the patch as a "cvs -u diff" ?

yes. And please remove the initial assignment of len.

Regards

Marcel




-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

2004-02-23 13:41:14

by James Courtier-Dutton

[permalink] [raw]
Subject: Re: [Bluez-devel] [PATCH] Fix some bugs in hcidump.

Marcel Holtmann wrote:
> Hi James,
>
>
>>Attached is a patch to apply to bluez-hcidump-1.5/parser/sdp.c
>>
>>It fixes some of the printout.
>
>
> please always do the diff againts the CVS version.
>
>
>>--- sdp.c.org 2004-02-23 02:56:03.667767736 +0000
>>+++ sdp.c 2004-02-23 03:15:48.787602136 +0000
>>@@ -324,6 +324,7 @@
>> printf("pat");
>>
>> if (parse_de_hdr(frm, &n1) == SDP_DE_SEQ) {
>>+ len = frm->len;
>> while (len - frm->len < n1 ) {
>> if (parse_de_hdr(frm,&n2) == SDP_DE_UUID) {
>> print_uuid(n2, frm);
>
>
> Your change means this
>
> while (n1 > 0) {
> ...
> }
>
> If this is what you want then do it this way and remove unneeded
> variables. Give me a short description what this changes do and why you
> did this change.
>
> Regards
>
> Marcel
>
>

while (len - frm->len < n1)
is NOT the same as
while (n1 > 0)

Each call to parse_de_hdr and print_uuid changes the value of frm->len.
So, each time round the while loop (len - frm->len) becomes larger.

The n1 value is set by the previous line
"if (parse_de_hdr(frm, &n1) == SDP_DE_SEQ) {"

This means we have n1 bytes of data we wish to parse inside the while loop.
So, we want to start the while loop with (len - frm->len) == 0
Each time round the loop (len - frm->len) will increase( due to calls to
parse_de_hdr and print_uuid) , and the loop will exit when (len -
frm->len) >= n1, which is what we want.

If we fail to set "len = frm->len;" just before the while loop, the
previous line
"if (parse_de_hdr(frm, &n1) == SDP_DE_SEQ) {"
changes frm->len, so the "int len = frm->len;" at the beginning of the
function is no longer correct.
I.E. len != frm->len after the "if (parse_de_hdr(frm, &n1) ==
SDP_DE_SEQ) {" statement.

I hope this explanation is clear.

Do you want me to resubmit the patch as a "cvs -u diff" ?

Cheers
James

2004-02-23 07:42:21

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [Bluez-devel] [PATCH] Fix some bugs in hcidump.

Hi James,

> Attached is a patch to apply to bluez-hcidump-1.5/parser/sdp.c
>
> It fixes some of the printout.

please always do the diff againts the CVS version.

> --- sdp.c.org 2004-02-23 02:56:03.667767736 +0000
> +++ sdp.c 2004-02-23 03:15:48.787602136 +0000
> @@ -324,6 +324,7 @@
> printf("pat");
>
> if (parse_de_hdr(frm, &n1) == SDP_DE_SEQ) {
> + len = frm->len;
> while (len - frm->len < n1 ) {
> if (parse_de_hdr(frm,&n2) == SDP_DE_UUID) {
> print_uuid(n2, frm);

Your change means this

while (n1 > 0) {
...
}

If this is what you want then do it this way and remove unneeded
variables. Give me a short description what this changes do and why you
did this change.

Regards

Marcel




-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel