All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: Alec Brown <alec.r.brown@oracle.com>
Cc: The development of GNU GRUB <grub-devel@gnu.org>,
	daniel.kiper@oracle.com, darren.kenny@oracle.com
Subject: Re: [PATCH 5/7] grub-core/net/net.c: Fix uninitialized scalar variable
Date: Tue, 15 Mar 2022 20:16:01 -0500	[thread overview]
Message-ID: <20220315201601.2b2828a4@crass-HP-ZBook-15-G2> (raw)
In-Reply-To: <1647375849-24164-6-git-send-email-alec.r.brown@oracle.com>

On Tue, 15 Mar 2022 16:24:07 -0400
Alec Brown <alec.r.brown@oracle.com> wrote:

> In the function grub_net_ipv6_get_link_local(), grub_net_network_level_address_t
> addr is called but isn't being initialized. To prevent contents of this
> structure from being filled with junk data from the stack, we can initialize it
> to 0 by setting addr to {};
> 
> Fixes: CID 375033
> 
> Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
> ---
>  grub-core/net/net.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/grub-core/net/net.c b/grub-core/net/net.c
> index 4d3eb5c1a..4e93365a7 100644
> --- a/grub-core/net/net.c
> +++ b/grub-core/net/net.c
> @@ -287,7 +287,7 @@ grub_net_ipv6_get_link_local (struct grub_net_card *card,
>    struct grub_net_network_level_interface *inf;
>    char *name;
>    char *ptr;
> -  grub_net_network_level_address_t addr;
> +  grub_net_network_level_address_t addr = {};
>  
>    addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6;
>    addr.ipv6[0] = grub_cpu_to_be64_compile_time (0xfe80ULL << 48);

This seems not quite necessary. The local "addr" is initialized just
below its initialization, so "junk" data doesn't matter. Only the
"option" member is not initialized, so we could just add another line to
initialize that.

The "{}" syntax seems to not be used much either, "{0}" being
preferred, but also not used much.

I think I remember Vladimir saying that GRUB doesn't use initializers,
but there are some in the code, so perhaps this isn't a thing
anymore.

Another option, which would be my preference, would be to move the 3
lines below the declaraction of "addr" into the initializer and use
C99's designated initializer, so something like:

  grub_net_network_level_address_t addr = {
    .type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV6,
    .ipv6 = {
      grub_cpu_to_be64_compile_time (0xfe80ULL << 48),
      grub_net_ipv6_get_id (hwaddr)
    }
  };

There is precedent for using function calls in initializers
(net/dns.c:453), but its also rare.

Daniel, do you have a preference here?

Glenn


  reply	other threads:[~2022-03-16  1:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-15 20:24 [PATCH 0/7] Fix coverity uninitialized scalar variable bugs in grub-core Alec Brown
2022-03-15 20:24 ` [PATCH 1/7] grub-core/loader/i386/bsd.c: Fix uninitialized scalar variable Alec Brown
2022-03-15 20:24 ` [PATCH 2/7] grub-core/loader/i386/pc/linux.c: " Alec Brown
2022-03-15 20:24 ` [PATCH 3/7] grub-core/net/arp.c: " Alec Brown
2022-03-15 20:24 ` [PATCH 4/7] grub-core/loader/i386/xnu.c: " Alec Brown
2022-03-15 20:24 ` [PATCH 5/7] grub-core/net/net.c: " Alec Brown
2022-03-16  1:16   ` Glenn Washburn [this message]
2022-03-17 21:20     ` Daniel Kiper
2022-03-15 20:24 ` [PATCH 6/7] grub-core/loader/i386/xnu.c: " Alec Brown
2022-03-15 20:24 ` [PATCH 7/7] grub-core/net/bootp.c: " Alec Brown
2022-03-15 20:32 ` [PATCH 0/7] Fix coverity uninitialized scalar variable bugs in grub-core Darren Kenny

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-all 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=20220315201601.2b2828a4@crass-HP-ZBook-15-G2 \
    --to=development@efficientek.com \
    --cc=alec.r.brown@oracle.com \
    --cc=daniel.kiper@oracle.com \
    --cc=darren.kenny@oracle.com \
    --cc=grub-devel@gnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.