From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JMWoS-0003NF-9I for mharc-grub-devel@gnu.org; Tue, 05 Feb 2008 18:02:48 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JMWoQ-0003Ko-7q for grub-devel@gnu.org; Tue, 05 Feb 2008 18:02:46 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JMWoP-0003KJ-6B for grub-devel@gnu.org; Tue, 05 Feb 2008 18:02:45 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JMWoP-0003K9-1r for grub-devel@gnu.org; Tue, 05 Feb 2008 18:02:45 -0500 Received: from mailout01.sul.t-online.de ([194.25.134.80] helo=mailout01.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JMWoO-00045d-8r for grub-devel@gnu.org; Tue, 05 Feb 2008 18:02:44 -0500 Received: from fwd29.aul.t-online.de by mailout01.sul.t-online.com with smtp id 1JMWoL-0004pA-02; Wed, 06 Feb 2008 00:02:41 +0100 Received: from [10.3.2.2] (Va06M+Zd8hvGYosx3tJKLKNk4ho8yqXlH5-XbnPhjwT83IzQrf8lUwl071JWMt5ZhH@[217.235.241.44]) by fwd29.aul.t-online.de with esmtp id 1JMWoF-0zaP7w0; Wed, 6 Feb 2008 00:02:35 +0100 Message-ID: <47A8EB0D.6070103@t-online.de> Date: Wed, 06 Feb 2008 00:02:37 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.11) Gecko/20071128 SeaMonkey/1.1.7 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------070905030208020303060305" X-ID: Va06M+Zd8hvGYosx3tJKLKNk4ho8yqXlH5-XbnPhjwT83IzQrf8lUwl071JWMt5ZhH X-TOI-MSGID: c77c88c3-9de3-4880-bdb4-0586897d5589 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] Fix crash on open of nonexisting tar/cpio file, fix cpio trailer detection X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Feb 2008 23:02:46 -0000 This is a multi-part message in MIME format. --------------070905030208020303060305 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Two issues found in current CVS: 1. Booting a grub2-mkrescue floppy crashes if "(memdisk)/boot/grub/grub.cfg" does not exist. This is because grub_cpio_open does not set grub_errno if a file does not exist. 2. The cpio format may not work. Header scan finishes early if data size is empty (directory, empty file). The cpio format uses the name "TRAILER!!!" to mark the last block. This patch fixes both issues. "grub-mkrescue --image-type=floppy" now works with both tar and cpio memdisk. Cpio was tested with this change to grub-mkrescue: - tar -C ${aux_dir} -cf ${memdisk_img} boot + ( cd ${aux_dir} && find boot | cpio -o > ${memdisk_img} ) Open issues not fixed in this patch: - Directory detection relies on a trailing '/' in path name. This works for typical tar files, but not for cpio. As a consequence, tab completion and "ls -l" are not correct. The "mode" in the header should be checked instead. - CPIO would not work on big endian architectures yet. Christian 2008-02-05 Christian Franke * fs/cpio.c (grub_cpio_find_file): Return GRUB_ERR_NONE and (*ofs = 0) instead of GRUB_ERR_FILE_NOT_FOUND on last block of a cpio or tar stream. Check for "TRAILER!!!" instead of any empty data block to detect last block of a cpio stream. (grub_cpio_dir): Fix constness of variable np. (grub_cpio_open): Return GRUB_ERR_FILE_NOT_FOUND if cpio or tar trailer is detected. This fixes a crash on open of a non existing file. --------------070905030208020303060305 Content-Type: text/x-patch; name="grub2-cpio-eof.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-cpio-eof.patch" --- grub2.orig/fs/cpio.c 2008-02-03 20:29:51.718750000 +0100 +++ grub2/fs/cpio.c 2008-02-05 22:59:50.031250000 +0100 @@ -98,11 +98,6 @@ grub_cpio_find_file (struct grub_cpio_da return grub_error (GRUB_ERR_BAD_FS, "Invalid cpio archive"); data->size = (((grub_uint32_t) hd.filesize_1) << 16) + hd.filesize_2; - if (data->size == 0) - { - *ofs = 0; - return GRUB_ERR_FILE_NOT_FOUND; - } if (hd.namesize & 1) hd.namesize++; @@ -117,6 +112,13 @@ grub_cpio_find_file (struct grub_cpio_da return grub_errno; } + if (data->size == 0 && hd.mode == 0 && hd.namesize == 11 + 1 + && ! grub_memcmp(*name, "TRAILER!!!", 11)) + { + *ofs = 0; + return GRUB_ERR_NONE; + } + data->dofs = data->hofs + sizeof (hd) + hd.namesize; *ofs = data->dofs + data->size; if (data->size & 1) @@ -133,7 +135,7 @@ grub_cpio_find_file (struct grub_cpio_da if (!hd.name[0]) { *ofs = 0; - return GRUB_ERR_FILE_NOT_FOUND; + return GRUB_ERR_NONE; } if (grub_memcmp (hd.magic, MAGIC_USTAR, sizeof (MAGIC_USTAR) - 1)) @@ -188,7 +190,8 @@ grub_cpio_dir (grub_device_t device, con { struct grub_cpio_data *data; grub_uint32_t ofs; - char *prev, *name, *np; + char *prev, *name; + const char *np; int len; #ifndef GRUB_UTIL @@ -275,7 +278,10 @@ grub_cpio_open (grub_file_t file, const goto fail; if (!ofs) - break; + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found"); + break; + } if (grub_strcmp (name + 1, fn) == 0) { --------------070905030208020303060305--