From: Laszlo Ersek <lersek@redhat.com>
To: Jiaxin Wu <Jiaxin.wu@intel.com>, edk2-devel@lists.01.org
Cc: Wu Hao A <hao.a.wu@intel.com>, Ye Ting <ting.ye@intel.com>,
Fu Siyuan <siyuan.fu@intel.com>,
Gao Liming <liming.gao@intel.com>
Subject: Re: [PATCH v1 1/2] MdeModulePkg/NetLib.h: Fix the possible NULL pointer dereference issue.
Date: Tue, 15 Jan 2019 11:29:45 +0100 [thread overview]
Message-ID: <953600c3-5346-3d17-cdaa-9574c3d94d14@redhat.com> (raw)
In-Reply-To: <20190115012613.16748-2-Jiaxin.wu@intel.com>
Hi Jiaxin,
On 01/15/19 02:26, Jiaxin Wu wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1456
>
> For the NET_LIST_FOR_EACH & NET_LIST_FOR_EACH_SAFE, "Entry" should be
> checked whether it's NULL or not instead of using the pointer directly.
>
> Cc: Wu Hao A <hao.a.wu@intel.com>
> Cc: Gao Liming <liming.gao@intel.com>
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Fu Siyuan <siyuan.fu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
> ---
> MdeModulePkg/Include/Library/NetLib.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h
> index 0977973921..5b1307553a 100644
> --- a/MdeModulePkg/Include/Library/NetLib.h
> +++ b/MdeModulePkg/Include/Library/NetLib.h
> @@ -616,21 +616,21 @@ NetRandomInitSeed (
>
> //
> // Iterate through the double linked list. It is NOT delete safe
> //
> #define NET_LIST_FOR_EACH(Entry, ListHead) \
> - for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
> + for(Entry = (ListHead)->ForwardLink; Entry != (ListHead), Entry != NULL; Entry = Entry->ForwardLink)
(1) The linked list from BaseLib (LIST_ENTRY) always has at least one
element (the head element), and the list is empty if the head element
points back to itself. In other words, ForwardLink may never be NULL.
So why is it necessary to check against that case here?
(2) If the NULL check is indeed necessary for some reason, then we
should write
Entry != (ListHead) && Entry != NULL
in the controlling expression. Because, with the comma operator, the
(Entry != (ListHead)) expression would be evaluated, but its result
would be ignored.
Thanks,
Laszlo
>
> //
> // Iterate through the double linked list. This is delete-safe.
> // Don't touch NextEntry. Also, don't use this macro if list
> // entries other than the Entry may be deleted when processing
> // the current Entry.
> //
> #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
> - for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \
> - Entry != (ListHead); \
> + for(Entry = (ListHead)->ForwardLink, (Entry != NULL) ? (NextEntry = Entry->ForwardLink) : (Entry = NULL); \
> + Entry != (ListHead), Entry != NULL; \
> Entry = NextEntry, NextEntry = Entry->ForwardLink \
> )
>
> //
> // Make sure the list isn't empty before getting the first/last record.
>
next prev parent reply other threads:[~2019-01-15 10:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-15 1:26 [PATCH v1 0/2] Fix the possible NULL pointer dereference issue Jiaxin Wu
2019-01-15 1:26 ` [PATCH v1 1/2] MdeModulePkg/NetLib.h: " Jiaxin Wu
2019-01-15 10:29 ` Laszlo Ersek [this message]
2019-01-16 8:23 ` Wu, Jiaxin
2019-01-15 1:26 ` [PATCH v1 2/2] MdeModulePkg/Dhcp4Dxe: Use NET_LIST_FOR_EACH instead of NET_LIST_FOR_EACH_SAFE Jiaxin Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=953600c3-5346-3d17-cdaa-9574c3d94d14@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox