[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp,
From: |
Daniel Mierswa |
Subject: |
[PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp |
Date: |
Wed, 21 Jan 2009 13:08:32 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20090103) |
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.
--
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
Index: kern/misc.c
===================================================================
--- kern/misc.c (revision 1952)
+++ kern/misc.c (working copy)
@@ -194,7 +194,7 @@
while (*s1 && *s2)
{
if (*s1 != *s2)
- return (int) *s1 - (int) *s2;
+ break;
s1++;
s2++;
@@ -212,7 +212,7 @@
while (*s1 && *s2 && --n)
{
if (*s1 != *s2)
- return (int) *s1 - (int) *s2;
+ break;
s1++;
s2++;
@@ -222,21 +222,36 @@
}
int
-grub_strncasecmp (const char *s1, const char *s2, int c)
+grub_strcasecmp (const char *s1, const char *s2)
{
- int p = 1;
+ while (*s1 && *s2)
+ {
+ if (grub_tolower (*s1) != grub_tolower (*s2))
+ break;
+
+ s1++;
+ s2++;
+ }
- 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 == 0)
+ return 0;
+
+ while (*s1 && *s2 && --n)
{
if (grub_tolower (*s1) != grub_tolower (*s2))
- return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
+ break;
s1++;
s2++;
- p++;
}
- return (int) *s1 - (int) *s2;
+ return (int) grub_tolower (*s1) - (int) grub_tolower (*s2);
}
char *
Index: include/grub/misc.h
===================================================================
--- 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
===================================================================
--- commands/search.c (revision 1952)
+++ commands/search.c (working copy)
@@ -115,7 +115,7 @@
(fs->uuid) (dev, &uuid);
if (grub_errno == GRUB_ERR_NONE && uuid)
{
- if (grub_strcmp (uuid, key) == 0)
+ if (grub_strcasecmp (uuid, key) == 0)
{
/* Found! */
count++;
- [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp,
Daniel Mierswa <=
- Re: [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp, Pavel Roskin, 2009/01/21
- Re: [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp, Daniel Mierswa, 2009/01/23
- Re: [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp, Pavel Roskin, 2009/01/26
- Re: [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp, Daniel Mierswa, 2009/01/26
- Re: [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp, Pavel Roskin, 2009/01/27
- Re: [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp, Pavel Roskin, 2009/01/27
- Re: [PATCH] caseless uuid detection, fixed wrong behaviour for strncasecmp, added strcasecmp, ebik, 2009/01/28