buglwIP - A Lightweight TCP/IP stack - Bugs: bug #62832, Allow NULL buffer to...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #62832: Allow NULL buffer to pbuf_get_contiguous()

Submitter:  Colin Foster <colin_foster_ia>
Submitted:  Thu 28 Jul 2022 06:40:23 PM UTC
   
 
Category:  pbufs Severity:  3 - Normal
Item Group:  Change Request Status:  Fixed
Privacy:  Public Assigned to:  goldsimon
Open/Closed:  Closed Planned Release:  2.2.1
lwIP version:  git head

Thu 12 Oct 2023 06:26:20 AM UTC, comment #4: 

Re comment #3: I don't think that's a problem: the caller can always check p->tot_len before (or after) if that's really a problem. And existing users won't pass a NULL pointer.

I think the idea is good. Pushed, thanks for reporting!

Simon Goldschmidt <goldsimon>
Group administrator
Tue 23 Aug 2022 02:46:04 AM UTC, comment #3: 

If pbuf_get_contiguous returns null, the caller may mistakenly think that there is not enough data. You can rewrite a new function and let the caller call it according to his own needs.

wuchangsheng <wuchangsheng>
Mon 22 Aug 2022 03:24:14 PM UTC, comment #2: 

comment #1:

> When the required data spans more than one pbuf, null is passed in and the data cannot be copied out


That's the point I address below. If data spans more than one pbuf, NULL would be returned in which case further action (allocating a buffer on the stack, for example) would become necessary. But in cases where the payloads almost never (or actually never) span multiple pbufs, why force the user to always allocate a separate buffer that'll never get used?

Colin Foster <colin_foster_ia>
Mon 22 Aug 2022 02:53:19 PM UTC, comment #1: 

When the required data spans more than one pbuf, null is passed in and the data cannot be copied out

wuchangsheng <wuchangsheng>
Thu 28 Jul 2022 06:40:23 PM UTC, original submission:  

The pbuf_get_contiguous currently requires a non-NULL buffer and a non-zero buffer size:

https://git.savannah.nongnu.org/cgit/lwip.git/tree/src/core/pbuf.c#n1111

It could be quite useful if an application could call it with NULL / 0, thus avoiding pbuf_copy_partial if possible, as well as memory allocation.

For instance:


struct foo *foo = pbuf_get_contiguous(pbuf, NULL, 0, sizeof(*foo), offset);
if (!foo)
{
  // error condition / malloc / stack call / etc
}


As it currently stands, additional stack would be required. For instance:


struct foo foo;
struct foo *pfoo = pbuf_get_contiguous(pbuf, &foo, sizeof(foo), sizeof(foo), offset);


Colin Foster <colin_foster_ia>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by wuchangsheng (Posted a comment)
  • -email is unavailable- added by colin_foster_ia (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-10-12 goldsimon StatusNone Fixed
        Assigned toNone goldsimon
        Open/ClosedOpen Closed
        Planned ReleaseNone 2.2.1

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code