Received: from list by lists.gnu.org with archive (Exim 4.71) id 1chBTn-00037c-Gh for mharc-grub-devel@gnu.org; Fri, 24 Feb 2017 03:43:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1chBTl-000362-CI for grub-devel@gnu.org; Fri, 24 Feb 2017 03:43:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1chBTi-0003DS-9D for grub-devel@gnu.org; Fri, 24 Feb 2017 03:43:53 -0500 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:32834) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1chBTi-0003Cx-19 for grub-devel@gnu.org; Fri, 24 Feb 2017 03:43:50 -0500 Received: by mail-lf0-x242.google.com with SMTP id j2so990380lfe.0 for ; Fri, 24 Feb 2017 00:43:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qD4of95ylkdMTMx73jk6X1LGQe93XWJy7LTvn45boMs=; b=c+fZ+Cr/x0vzud44CE+pf6IQ3QJ4HHz4sWYZ24RjfZ8E+5M2WJKSpELcN5l+HUaD9M qaC9Mw1E/J5sdpFUJ9M4fJHnqqKdHksxY7sIpO/QLMnjnd+6oqoO/kNkxro7dmb/yfHV AjANqngpNENUGSxg2F1wMOg9GhJpvjRYX5rdwEdhVv+cI5SUl5A/tTXTBj9jiF0Sz89r FpryRjXk992JXOWGnYealOKrz4Rm6A6WL2AsMcGn7YpVeARklJoJm4eBn3D7Ks6gZ18G +9GVwKs7TCczhZFbNCcCWgC6fGDEgRUtcAxbpjrFMDcnO9k6pb5x5SVJUGIOFFEQZPmK RirA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qD4of95ylkdMTMx73jk6X1LGQe93XWJy7LTvn45boMs=; b=cjh/NI9g+A0l6RvVEr/yUg/fgDNzQOQC6M5otyiB28XeCZSTPvcMjKcxaTdxCqaJIz JX2Sr2NLv3s6N0z1yz5iVMJQAeEQwu3USt3pIhDnqm5X1GKtpvSFmZ/H8o/+IWV0ZTma qxQBjf3ptZ4VCFWOMmn/KNU4LpJgy5sfg0d/Xaf5XXaSsnF2oPHK5+OdJcjNAnoXj9ps Ens7Z7dRUXWx2wgRXr5xk0Fp04Z/Z1tcqEz8r6Jg01MB9fmzwMiG6Ma7po3G3i4ADkXj 2mIjOZYXE+X3LabyjhhOcUCtwZU4KiEEPBV5n4vdKiQnGaLC3IA3TolVn7MFk9e7Xy2t R6tQ== X-Gm-Message-State: AMke39kyrA1PSUS/WmgsLUiZxv+We1OApWy5+I0HMnCVpv/e7aGZukXH6iSW6oIRhSqkew== X-Received: by 10.46.1.201 with SMTP id f70mr401718lji.21.1487925827877; Fri, 24 Feb 2017 00:43:47 -0800 (PST) Received: from localhost.localdomain (ppp109-252-90-129.pppoe.spdop.ru. [109.252.90.129]) by smtp.gmail.com with ESMTPSA id e18sm1854667lfg.22.2017.02.24.00.43.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Feb 2017 00:43:47 -0800 (PST) From: Andrei Borzenkov To: grub-devel@gnu.org Cc: mchang@suse.com Subject: [PATCH] efi: strip off final NULL from File Path in grub_efi_get_filename Date: Fri, 24 Feb 2017 11:43:40 +0300 Message-Id: <1487925820-32432-1-git-send-email-arvidjaar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487919270-26971-1-git-send-email-arvidjaar@gmail.com> References: <1487919270-26971-1-git-send-email-arvidjaar@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::242 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Feb 2017 08:43:54 -0000 UEFI 2.6 9.3.6.4 File Path Media Device Path says that Path Name is "A NULL-terminated Path string including directory and file names". Strip final NULL from Path Name in each File Path node when constructing full path. To be on safe side, strip all of them. Fixes failure chainloading grub from grub, when loaded grub truncates image path and does not find its grub.cfg. https://bugzilla.opensuse.org/show_bug.cgi?id=1026344 This was triggered by commit ce95549cc54b5d6f494608a7c390dba3aab4fba7; before it we built Path Name without trailing NULL, and apparently all other bootloaders use single File Path node, thus not exposing this bug. --- @Vladimir, @Daniel - this fixes regression in rc1 and is real fix for the mentioned problem (previous patch only fixed the case of grub - grub chainloading, this patch should properly parse image path also when called from other EFI application). grub-core/kern/efi/efi.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c index caf9bcc..d467785 100644 --- a/grub-core/kern/efi/efi.c +++ b/grub-core/kern/efi/efi.c @@ -366,6 +366,9 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) len = ((GRUB_EFI_DEVICE_PATH_LENGTH (dp) - 4) / sizeof (grub_efi_char16_t)); fp = (grub_efi_file_path_device_path_t *) dp; + /* According to EFI spec Path Name is NULL terminated */ + while (len > 0 && fp->path_name[len - 1] == 0) + len--; p = (char *) grub_utf16_to_utf8 ((unsigned char *) p, fp->path_name, len); } -- tg: (2fb8cd2..) u/efi-strip-final-NULL-from-file-path (depends on: master)