Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JHoak-0003sF-Vf for mharc-grub-devel@gnu.org; Wed, 23 Jan 2008 18:01:11 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JHoak-0003qd-15 for grub-devel@gnu.org; Wed, 23 Jan 2008 18:01:10 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JHoaj-0003pY-JH for grub-devel@gnu.org; Wed, 23 Jan 2008 18:01:09 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JHoaj-0003pO-AQ for grub-devel@gnu.org; Wed, 23 Jan 2008 18:01:09 -0500 Received: from wa-out-1112.google.com ([209.85.146.183]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JHoai-0007L7-NA for grub-devel@gnu.org; Wed, 23 Jan 2008 18:01:09 -0500 Received: by wa-out-1112.google.com with SMTP id k34so5304737wah.10 for ; Wed, 23 Jan 2008 15:01:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type; bh=AnQ+svw3gIReLBuI9gboqZ8ywn7TXVF+ZurJsBiRLD4=; b=Kb5ErtCBV+KsG6fvJP6QdpViUbRXSoc32VUGrnAwsfRcKTEyFbzE2ZjH6PhK39Qkovap4CC5jjCG0P1ZfgVoQokZj8drTiNybo00q8j2G3q+mn43yk8RE3Z/T6VOvX3iFBSIfAo2WfS2C3EqIKpKMppjsE/xboMnjU+EF9pDjuM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type; b=P79JfDpSjJuqm0jShh96d0rS3u38nc8u/ccA3FLQjWEhLT6sM8HievezaAHQYibQkUahIeA2F1O7TV0pVfrL/hXjxHDnExTn6mfU1alOO7oXips5ZM2BdH0AbIu+D1VJEZ1tsjTMdJfrNlKOU7ml22RQgp0z1Aa0ZF7aGoTszNY= Received: by 10.114.89.1 with SMTP id m1mr8295367wab.77.1201129257821; Wed, 23 Jan 2008 15:00:57 -0800 (PST) Received: by 10.114.254.10 with HTTP; Wed, 23 Jan 2008 15:00:57 -0800 (PST) Message-ID: <94a0ccbc0801231500g752f72acodc37c733726d8919@mail.gmail.com> Date: Wed, 23 Jan 2008 23:00:57 +0000 From: "Oleg Strikov" To: grub-devel@gnu.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_36411_23287204.1201129257780" X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: /kern/file.c BUG 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: Wed, 23 Jan 2008 23:01:10 -0000 ------=_Part_36411_23287204.1201129257780 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Incorrect behavior of grub_file_open () function in e.g. loop context: char *file_names[] = { "(hd0,1)/file1", //file do not exist "(hd0,1)/file2" //file exist }; grub_file_t file; int i; for (i = 0; i < 2; i++) { file = grub_file_open (file_names[i]); if (file) {...} } There, we should get positive return in the second case (i == 1), but grub_file_open() returns 0. Using gdb i've found that this problem connected with incorrect errno check in /kern/file.c Let's look: >grub_file_t >grub_file_open (const char *name) >{ > grub_device_t device; > grub_file_t file = 0; > char *device_name; > char *file_name; > device_name = grub_file_get_device_name (name); > if (grub_errno) > return 0; But, we DO NOT set grub_errno to 0 at the begining of the function, thats why next loop round it always returns 0 PATCH: --- ./grub2.stable/kern/file.c.orig 2008-01-23 22:30:17.850755634 +0000 +++ ./grub2.stable/kern/file.c 2008-01-23 22:45:17.788904935 +0000 @@ -59,6 +59,8 @@ grub_file_open (const char *name) char *device_name; char *file_name; + grub_errno = 0; + device_name = grub_file_get_device_name (name); if (grub_errno) return 0; ------=_Part_36411_23287204.1201129257780 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Incorrect behavior of grub_file_open () function in e.g. loop context:

char *file_names[] =
{
"(hd0,1)/file1", //file do not exist
"(hd0,1)/file2"  //file exist
};
grub_file_t file;
int i;
for (i = 0; i < 2; i++)
{
     file  = grub_file_open (file_names[i]);
     if (file) {...}
}

There, we should get positive return in the second case (i == 1), but grub_file_open() returns 0.

Using gdb i've found that this problem connected with incorrect errno check in /kern/file.c

Let's look:

>grub_file_t
>grub_file_open (const char *name)
>{
>  grub_device_t device;
>  grub_file_t file = 0;
>  char *device_name;
>  char *file_name;

>  device_name = grub_file_get_device_name (name);
>  if (grub_errno)
>    return 0;

But, we DO NOT set grub_errno to 0 at the begining of the function, thats why next loop round it always returns 0



PATCH:
--- ./grub2.stable/kern/file.c.orig    2008-01-23 22:30:17.850755634 +0000
+++ ./grub2.stable/kern/file.c    2008-01-23 22:45:17.788904935 +0000
@@ -59,6 +59,8 @@ grub_file_open (const char *name)
   char *device_name;
   char *file_name;
 
+  grub_errno = 0;
+
   device_name = grub_file_get_device_name (name);
   if (grub_errno)
     return 0;
------=_Part_36411_23287204.1201129257780--