Possible bug in LWIP version of wiced_packet_get_data

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable
[SDK-2.3.1]

There seems to be a bug in wiced_packet_get_data, where data_length is assigned the length of the entire packets netbuf, rather than individual contiguous pbuf:

*data_length = packet->p->tot_len;

...

*data_length = (uint16_t)(*data_length - offset);

E.g., if I have a netbuf of 2 pbufs of 5 bytes, and read at offset 0:

data_length = 10

available_length = 10

data = ... pbuf (5 bytes)

So I will read past the end of data if I try to read more than 5 bytes.

I think the initial value should be the length of the current pbuf:

*data_length = packet->p->len;

...

*data_length = (uint16_t)(*data_length - offset);

So same read at 0 would be:

data_length = 5

available_length = 10

data = ... pbuf (5 bytes)

0 Likes
5 Replies
Anonymous
Not applicable
WICED does not officially support chained buffers and using them will cause unpredictable behaviour.
0 Likes
Anonymous
Not applicable
packet->p always points the top of pBuf memory chain.

packet->ptr points the current node of pBuf memory chain.

*data_length requires current nodes memory size.

So, I think

*data_length = packet->p->tot_len;

should be

*data_length = packet->ptr->len;
0 Likes
Anonymous
Not applicable
WICED currently does not support chained packet buffers and much of the code assumes that tot_len and len are equal. In fact there are places that assert that p->tot_len == p->len.

That means we can change from using tot_len to len without affecting existing functionality but allows WICED to be better prepared for supporting chained packet buffers in the future.

An internal issue has been raised to review our use of tot_len and len.

Thank you for your feedback
0 Likes
Anonymous
Not applicable
WICED currently does not support chained packet buffers and so much of the code assumes that tot_len and len are equal. In fact there are places that assert that p->tot_len == p->len.

That means we can change from using tot_len to len without affecting existing functionality but allows WICED to be better prepared for supporting chained packet buffers in the future.

An internal issue has been raised to review our use of tot_len and len.

Thank you for your feedback

You are referring to the internals of the LWIP netbuf, but does this mean that at the WICED API level:

1. calling wiced_tcp_receive() today always returns wiced packet with a single contiguous buffer?

2. passing this packet to wiced_packet_get_data will always return a pointer to this single buffer, and both the data_length and available_data_length will be the same, equal to the received amount of data in this packet?
0 Likes
Anonymous
Not applicable
1. Yes

2. Yes
0 Likes