lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] Potential NULL pointer access in ip4_frag.c


From: Patrick Klos
Subject: Re: [lwip-users] Potential NULL pointer access in ip4_frag.c
Date: Wed, 26 Apr 2017 09:56:56 -0400
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 4/26/2017 3:31 AM, Andreas Dinter wrote:

Hi,

When compiling ip4_frag.c with GCC option -Wnull-dereference, it complains with the following warning.

  ../../../lwIp/src/core/ipv4/ip4_frag.c:327:16: warning: potential null pointer dereference [-Wnull-dereference]

This refers to this line: prev->next = ipr->next;

In function:              ip_reass_dequeue_datagram()

I am using version 6.3.1 of GGC.

Can you please comment on this warning?


Not having access to that specific version of LwIP, I can only comment on what the compiler is PROBABLY trying to warn you about.  The only way the compiler can KNOW you're not dereferencing a null pointer is for you to check for null explicitly first, maybe something like this:
    LWIP_ASSERT("sanity check linked list", prev != NULL);
    if ((prev == null) || (ipr == null)
        return; // ignore if either of the pointers in null
    prev->next = ipr->next;
  }
    :    :    :
That would possibly get rid of your warning?  (I think if LWIP_ASSERT was enabled, the code generated by the macro expansion would be enough to stop the warning, at least for 'prev'?)

Patrick


reply via email to

[Prev in Thread] Current Thread [Next in Thread]