From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1LPbvi-0001Sl-TG for mharc-grub-devel@gnu.org; Wed, 21 Jan 2009 07:11:35 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LPbvd-0001RX-Tv for grub-devel@gnu.org; Wed, 21 Jan 2009 07:11:30 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LPbvb-0001R7-Iy for grub-devel@gnu.org; Wed, 21 Jan 2009 07:11:28 -0500 Received: from [199.232.76.173] (port=57807 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LPbva-0001Qu-Si for grub-devel@gnu.org; Wed, 21 Jan 2009 07:11:27 -0500 Received: from eta-ori.net ([91.121.142.51]:42897 helo=orion.eta-ori.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LPbva-00015w-BW for grub-devel@gnu.org; Wed, 21 Jan 2009 07:11:26 -0500 Received: by orion.eta-ori.net (Postfix, from userid 1006) id 04DD92E89B4; Wed, 21 Jan 2009 13:11:23 +0100 (CET) Received: from [IPv6:2001:6f8:10ae:0:217:31ff:fe81:8c8] (istari.kleinerfeigling.org [IPv6:2001:6f8:10ae:0:217:31ff:fe81:8c8]) by orion.eta-ori.net (Postfix) with ESMTPSA id B03892E5815 for ; Wed, 21 Jan 2009 13:11:18 +0100 (CET) Message-ID: <49771040.7010509@impulze.org> Date: Wed, 21 Jan 2009 13:08:32 +0100 From: Daniel Mierswa User-Agent: Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: grub-devel@gnu.org X-Enigmail-Version: 0.95.7 OpenPGP: id=ADF32F97 Content-Type: multipart/mixed; boundary="------------040602020501040700000200" X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp 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, 21 Jan 2009 12:11:31 -0000 This is a multi-part message in MIME format. --------------040602020501040700000200 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi list, during testing I found that the UUID is checked case-dependend in search.c, which is probably not wanted (I hope). Also the grub_strncasecmp function returned (int) *s1 - (int) *s2 which is wrong if you compare it to the C library strncasecmp. I fixed that and used the same algorithm which is used in grub_strncmp (Taking a grub_size_t instead of int and checked the decremented value in the loop). I also added strcasecmp for consistency reasons which is used by search.c now. I'd appreciate your your replies. --=20 Mierswa, Daniel If you still don't like it, that's ok: that's why I'm boss. I simply know better than you do. --- Linus Torvalds, comp.os.linux.advocacy, 1996/07/22 --------------040602020501040700000200 Content-Type: text/plain; name="caseless_uuid.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="caseless_uuid.patch" Index: kern/misc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- kern/misc.c (revision 1952) +++ kern/misc.c (working copy) @@ -194,7 +194,7 @@ while (*s1 && *s2) { if (*s1 !=3D *s2) - return (int) *s1 - (int) *s2; + break; =20 s1++; s2++; @@ -212,7 +212,7 @@ while (*s1 && *s2 && --n) { if (*s1 !=3D *s2) - return (int) *s1 - (int) *s2; + break; =20 s1++; s2++; @@ -222,21 +222,36 @@ } =20 int -grub_strncasecmp (const char *s1, const char *s2, int c) +grub_strcasecmp (const char *s1, const char *s2) { - int p =3D 1; + while (*s1 && *s2) + { + if (grub_tolower (*s1) !=3D grub_tolower (*s2)) + break; + =20 + s1++; + s2++; + } =20 - while (grub_tolower (*s1) && grub_tolower (*s2) && p < c) + return (int) grub_tolower (*s1) - (int) grub_tolower (*s2); +} + +int +grub_strncasecmp (const char *s1, const char *s2, grub_size_t n) +{ + if (n =3D=3D 0) + return 0; + =20 + while (*s1 && *s2 && --n) { if (grub_tolower (*s1) !=3D grub_tolower (*s2)) - return (int) grub_tolower (*s1) - (int) grub_tolower (*s2); + break; =20 s1++; s2++; - p++; } =20 - return (int) *s1 - (int) *s2; + return (int) grub_tolower (*s1) - (int) grub_tolower (*s2); } =20 char * Index: include/grub/misc.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- include/grub/misc.h (revision 1952) +++ include/grub/misc.h (working copy) @@ -45,7 +45,8 @@ int EXPORT_FUNC(grub_memcmp) (const void *s1, const void *s2, grub_size_= t n); int EXPORT_FUNC(grub_strcmp) (const char *s1, const char *s2); int EXPORT_FUNC(grub_strncmp) (const char *s1, const char *s2, grub_size= _t n); -int EXPORT_FUNC(grub_strncasecmp) (const char *s1, const char *s2, int c= ); +int EXPORT_FUNC(grub_strcasecmp) (const char *s1, const char *s2); +int EXPORT_FUNC(grub_strncasecmp) (const char *s1, const char *s2, grub_= size_t n); char *EXPORT_FUNC(grub_strchr) (const char *s, int c); char *EXPORT_FUNC(grub_strrchr) (const char *s, int c); int EXPORT_FUNC(grub_strword) (const char *s, const char *w); Index: commands/search.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- commands/search.c (revision 1952) +++ commands/search.c (working copy) @@ -115,7 +115,7 @@ (fs->uuid) (dev, &uuid); if (grub_errno =3D=3D GRUB_ERR_NONE && uuid) { - if (grub_strcmp (uuid, key) =3D=3D 0) + if (grub_strcasecmp (uuid, key) =3D=3D 0) { /* Found! */ count++; --------------040602020501040700000200--