grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: "Vladimir 'phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: [PATCH] btrfs: avoid "used uninitialized" error with GCC7
Date: Mon, 03 Apr 2017 08:59:58 +0000	[thread overview]
Message-ID: <CAEaD8JNmPeJKX4RekgjsSnLCpLUSYanQ7S2JB6huCCZhDA9rZw@mail.gmail.com> (raw)
In-Reply-To: <1490978526-13303-1-git-send-email-arvidjaar@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2583 bytes --]

On Fri, Mar 31, 2017, 06:43 Andrei Borzenkov <arvidjaar@gmail.com> wrote:

> sblock was local and so considered new variable on every loop
> iteration.
>
> While on it, dynamically allocate buffer to reduce stack usage.
>
Looks good. Did you check all instances sizeof, so we don't have sizeof of
pointer?
Did you check return paths for free'ing on all of them?

>
>
> Closes: 50597
>
> ---
>  grub-core/fs/btrfs.c | 18 ++++++++++++------
>  1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
> index 9cffa91..99e81f9 100644
> --- a/grub-core/fs/btrfs.c
> +++ b/grub-core/fs/btrfs.c
> @@ -229,24 +229,29 @@ read_sblock (grub_disk_t disk, struct
> grub_btrfs_superblock *sb)
>  {
>    unsigned i;
>    grub_err_t err = GRUB_ERR_NONE;
> +  struct grub_btrfs_superblock *sblock;
> +
> +  sblock = grub_malloc (sizeof (*sblock));
> +  if (sblock == NULL)
> +    return grub_errno;
> +
>    for (i = 0; i < ARRAY_SIZE (superblock_sectors); i++)
>      {
> -      struct grub_btrfs_superblock sblock;
>        /* Don't try additional superblocks beyond device size.  */
> -      if (i && (grub_le_to_cpu64 (sblock.this_device.size)
> +      if (i && (grub_le_to_cpu64 (sblock->this_device.size)
>                 >> GRUB_DISK_SECTOR_BITS) <= superblock_sectors[i])
>         break;
>        err = grub_disk_read (disk, superblock_sectors[i], 0,
> -                           sizeof (sblock), &sblock);
> +                           sizeof (*sblock), sblock);
>        if (err == GRUB_ERR_OUT_OF_RANGE)
>         break;
>
> -      if (grub_memcmp ((char *) sblock.signature, GRUB_BTRFS_SIGNATURE,
> +      if (grub_memcmp ((char *) sblock->signature, GRUB_BTRFS_SIGNATURE,
>                        sizeof (GRUB_BTRFS_SIGNATURE) - 1) != 0)
>         break;
> -      if (i == 0 || grub_le_to_cpu64 (sblock.generation)
> +      if (i == 0 || grub_le_to_cpu64 (sblock->generation)
>           > grub_le_to_cpu64 (sb->generation))
> -       grub_memcpy (sb, &sblock, sizeof (sblock));
> +       grub_memcpy (sb, sblock, sizeof (*sblock));
>      }
>
>    if ((err == GRUB_ERR_OUT_OF_RANGE || !err) && i == 0)
> @@ -255,6 +260,7 @@ read_sblock (grub_disk_t disk, struct
> grub_btrfs_superblock *sb)
>    if (err == GRUB_ERR_OUT_OF_RANGE)
>      grub_errno = err = GRUB_ERR_NONE;
>
> +  grub_free (sblock);
>    return err;
>  }
>
> --
> tg: (8014b7b..) bug/50597 (depends on: master)
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 4761 bytes --]

  reply	other threads:[~2017-04-03  9:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31 16:42 [PATCH] btrfs: avoid "used uninitialized" error with GCC7 Andrei Borzenkov
2017-04-03  8:59 ` Vladimir 'phcoder' Serbinenko [this message]
2017-04-04 16:27   ` Andrei Borzenkov

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=CAEaD8JNmPeJKX4RekgjsSnLCpLUSYanQ7S2JB6huCCZhDA9rZw@mail.gmail.com \
    --to=phcoder@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).