All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: grub-devel@gnu.org
Subject: Re: Patch for getroot.c
Date: Sat, 26 Mar 2011 23:24:35 +0100	[thread overview]
Message-ID: <4D8E67A3.9040508@gmail.com> (raw)
In-Reply-To: <alpine.GSO.2.00.1102111154010.418879@oretfbsg>

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

On 11.02.2011 20:58, Seth Goldberg wrote:
> Hi,
>
>   When testing with UMEM_DEBUG set to default on Solaris, I discovered
> that find_root_device_from_libzfs() was maintaining a pointer to state
> that was freed when zpool_close() was called (specifically, the device
> path string, retrieved from an nvlist).  The path here fixes that and
> make this function a bit more bulletproof by testing for NULLs.  (Note
> that this returns memory that is not freed by the util programs that
> use it, but that's not unique to this patch -- all strings from
> grub_guess_root_device() aren't freed after they're used.)
>
Applied with some changes. Patch for the parts we don't have is
obviously skipped
> === modified file 'grub-core/kern/emu/getroot.c'
> --- grub-core/kern/emu/getroot.c    2011-01-12 02:57:53 +0000
> +++ grub-core/kern/emu/getroot.c    2011-02-11 19:48:23 +0000
> @@ -185,7 +185,7 @@
>  static char *
>  find_root_device_from_libzfs (const char *dir, struct stat *sbp)
>  {
> -  char *device;
> +  char *device = NULL;
>    char *poolname;
>    char *poolfs;
>
> @@ -224,9 +224,13 @@
>      if (nvlist_lookup_string (children[i], "path", &device) != 0)
>        error (1, errno, "nvlist_lookup_string (\"path\")");
>
> +        grub_dprintf("zfs", "device -> %s\n", device);
> +
>      struct stat st;
> -    if (stat (device, &st) == 0)
> +    if (stat (device, &st) == 0) {
> +          device = grub_strdup(device);
>        break;
> +        }
>
>      device = NULL;
>        }
> @@ -240,12 +244,15 @@
>
>  #if defined(__sun__)
>    /* If the device is a /dev/dsk path, convert it into a /dev/rdsk
> one */
> -  if (strncmp(device, "/dev/dsk/", 9) == 0) {
> -    device = xasprintf("/dev/rdsk/%s", device + 9);
> +  if (device != NULL && strncmp(device, "/dev/dsk/", 9) == 0) {
> +    char *newdevice = xasprintf("/dev/rdsk/%s", device + 9);
> +    grub_free(device);
> +    device = newdevice;
>    }
>  #endif
>
> -  grub_util_info("zfs path = %s", device);
> +  if (device != NULL)
> +    grub_util_info("zfs path = %s", device);
>
>    return device;
>  }
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

      reply	other threads:[~2011-03-26 22:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-11 19:58 Patch for getroot.c Seth Goldberg
2011-03-26 22:24 ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]

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=4D8E67A3.9040508@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 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.