From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1U25wx-0003f7-MQ for mharc-grub-devel@gnu.org; Sun, 03 Feb 2013 15:14:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U25wt-0003do-QV for grub-devel@gnu.org; Sun, 03 Feb 2013 15:14:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U25ws-0000Ij-Ee for grub-devel@gnu.org; Sun, 03 Feb 2013 15:13:59 -0500 Received: from mail-ea0-f179.google.com ([209.85.215.179]:53865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U25ws-0000IZ-5I for grub-devel@gnu.org; Sun, 03 Feb 2013 15:13:58 -0500 Received: by mail-ea0-f179.google.com with SMTP id d12so2377775eaa.38 for ; Sun, 03 Feb 2013 12:13:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:cc :subject:references:in-reply-to:x-enigmail-version:content-type; bh=OIMQyALtlaHyaItnkeIG2sNXOX1gOm7UFUH7n507cWo=; b=qUF9Hdt6gUEqiLnYN0D3j1wUSPizLJhJiHJ2tLdmTAGEhYxDf+g0QcvbHp1v/hCuXh 0282JB77Je7PvBC9vgsozAskdCHypYuUhwCOo8z/wITKUbsg2Uk0D93+y4HNqStUQ3NW /a4jaZWzmU9W8on9NtWVz777ZSLZdRqLnNab4GcRZjgKkBt68Ikg2hziu5/1RP6WUxbh UQWrXli4tFXeGIldwl+f08Eaj7lCshdrr4MWsXGWIjisPJ1Fu+7DGssveMkifglNSNnw CmMZ+rcuOXuxhwyv8gaugtfkjhyHXBbGIXuoTATZiIM0jekq1bj5JuiUo6sTlvAru9iJ jKHg== X-Received: by 10.14.5.12 with SMTP id 12mr6252787eek.36.1359922436912; Sun, 03 Feb 2013 12:13:56 -0800 (PST) Received: from debian.x201.phnet (vpn-global-012-dhcp.ethz.ch. [129.132.211.12]) by mx.google.com with ESMTPS id f6sm23782752eeo.7.2013.02.03.12.13.50 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 03 Feb 2013 12:13:55 -0800 (PST) Message-ID: <510EC4F1.9090604@gmail.com> Date: Sun, 03 Feb 2013 21:13:37 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121122 Icedove/10.0.11 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH] Fix prefix autodetection when booting from EFI CD-ROM References: <1359635040-23786-1-git-send-email-arvidjaar@gmail.com> In-Reply-To: <1359635040-23786-1-git-send-email-arvidjaar@gmail.com> X-Enigmail-Version: 1.4.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigC0AE72349764785314585350" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.215.179 Cc: Andrey Borzenkov , mchang@suse.com, mjg@redhat.com X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Feb 2013 20:14:02 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC0AE72349764785314585350 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 31.01.2013 13:24, Andrey Borzenkov wrote: > Fix autodetection of $prefix when booted from EFI CD-ROM. >=20 > Based on patch from Matthew Garrett, modified to not overwrite > memory returned by device path protocol handler and rebased to > current trunk. Due to legal issues we need Matthew Garrett, or someone from Red Hat, to send the patch. I wonder why this didn't happen before. >=20 > Additionally fixes potential memory leak - dup_dp was not deallocated > if device path was not found. >=20 > Signed-off-by: Andrey Borzenkov >=20 > --- > grub-core/disk/efi/efidisk.c | 121 +++++++++++++++++++++++-----------= -------- > 1 file changed, 66 insertions(+), 55 deletions(-) >=20 > diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.= c > index 98cd226..15c8109 100644 > --- a/grub-core/disk/efi/efidisk.c > +++ b/grub-core/disk/efi/efidisk.c > @@ -775,67 +775,78 @@ grub_efidisk_get_device_name (grub_efi_handle_t *= handle) > if (! ldp) > return 0; > =20 > - if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) =3D=3D GRUB_EFI_MEDIA_DEVICE_PAT= H_TYPE > - && (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp) > - =3D=3D GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE)) > + if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) =3D=3D GRUB_EFI_MEDIA_DEVICE_PAT= H_TYPE) > { > - struct grub_efidisk_get_device_name_ctx ctx; > - char *dev_name; > - grub_efi_device_path_t *dup_dp, *dup_ldp; > - grub_disk_t parent =3D 0; > - > - /* It is necessary to duplicate the device path so that GRUB > - can overwrite it. */ > - dup_dp =3D duplicate_device_path (dp); > - if (! dup_dp) > - return 0; > - > - dup_ldp =3D find_last_device_path (dup_dp); > - dup_ldp->type =3D GRUB_EFI_END_DEVICE_PATH_TYPE; > - dup_ldp->subtype =3D GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; > - dup_ldp->length[0] =3D sizeof (*dup_ldp); > - dup_ldp->length[1] =3D 0; > + int is_cdrom =3D 0; > =20 > - if (!get_diskname_from_path (dup_dp, device_name)) > - return 0; > - parent =3D grub_disk_open (device_name); > - grub_free (dup_dp); > - > - if (! parent) > - return 0; > - > - /* Find a partition which matches the hard drive device path. *= / > - ctx.partition_name =3D NULL; > - grub_memcpy (&ctx.hd, ldp, sizeof (ctx.hd)); > - if (ctx.hd.partition_start =3D=3D 0 > - && ctx.hd.partition_size =3D=3D grub_disk_get_size (parent)) > - { > - dev_name =3D grub_strdup (parent->name); > - } > - else > + switch (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp)) > { > - grub_partition_iterate (parent, grub_efidisk_get_device_name_iter, > - &ctx); > - > - if (! ctx.partition_name) > + case GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE: > + is_cdrom =3D 1; > + /* Intentionally fall through */ > + case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE: > { > + struct grub_efidisk_get_device_name_ctx ctx; > + char *dev_name; > + grub_efi_device_path_t *dup_dp, *dup_ldp; > + grub_disk_t parent =3D 0; > + > + /* It is necessary to duplicate the device path so that GRUB > + can overwrite it. */ > + dup_dp =3D duplicate_device_path (dp); > + if (! dup_dp) > + return 0; > + > + dup_ldp =3D find_last_device_path (dup_dp); > + dup_ldp->type =3D GRUB_EFI_END_DEVICE_PATH_TYPE; > + dup_ldp->subtype =3D GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE; > + dup_ldp->length[0] =3D sizeof (*dup_ldp); > + dup_ldp->length[1] =3D 0; > + > + if (!get_diskname_from_path (dup_dp, device_name)) > + { > + grub_free (dup_dp); > + return 0; > + } > + grub_free (dup_dp); > + if (is_cdrom) > + return grub_strdup (device_name); > + > + parent =3D grub_disk_open (device_name); > + if (! parent) > + return 0; > + > + /* Find a partition which matches the hard drive device path. = */ > + ctx.partition_name =3D NULL; > + grub_memcpy (&ctx.hd, ldp, sizeof (ctx.hd)); > + if (ctx.hd.partition_start =3D=3D 0 > + && ctx.hd.partition_size =3D=3D grub_disk_get_size (parent)) > + { > + dev_name =3D grub_strdup (parent->name); > + } > + else > + { > + grub_partition_iterate (parent, grub_efidisk_get_device_name_iter,= > + &ctx); > + > + if (! ctx.partition_name) > + { > + grub_disk_close (parent); > + return 0; > + } > + > + dev_name =3D grub_xasprintf ("%s,%s", parent->name, > + ctx.partition_name); > + grub_free (ctx.partition_name); > + } > grub_disk_close (parent); > - return 0; > - } > =20 > - dev_name =3D grub_xasprintf ("%s,%s", parent->name, > - ctx.partition_name); > - grub_free (ctx.partition_name); > + return dev_name; > + } > } > - grub_disk_close (parent); > - > - return dev_name; > - } > - else > - { > - /* This should be an entire disk. */ > - if (!get_diskname_from_path (dp, device_name)) > - return 0; > - return grub_strdup (device_name); > } > + /* This may be guessed device - floppy, cdrom or entire disk. */ > + if (!get_diskname_from_path (dp, device_name)) > + return 0; > + return grub_strdup (device_name); > } --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enigC0AE72349764785314585350 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAlEOxPEACgkQNak7dOguQgmPNwD+N/vVzcEDzjwi6g2++aX5BaKb PYKRGhbfAAi+cQPVP2QA/R1TZQQ99WLKQF938+0H3BTo+FiPBGzovSS69PjEmHui =9q/M -----END PGP SIGNATURE----- --------------enigC0AE72349764785314585350--