kernel32: CompareStringW should abort on the first nonmatching character to avoid invalid memory access.

Dmitry Timoshkov dmitry at baikal.ru
Fri Nov 13 06:36:54 CST 2015


For bug 37556.

Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
---
 libs/wine/sortkey.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/libs/wine/sortkey.c b/libs/wine/sortkey.c
index 17b5537..c459cea 100644
--- a/libs/wine/sortkey.c
+++ b/libs/wine/sortkey.c
@@ -223,6 +223,8 @@ static inline int compare_unicode_weights(int flags, const WCHAR *str1, int len1
         len1--;
         len2--;
     }
+    if (len1 && !*str1) len1--;
+    if (len2 && !*str2) len2--;
     return len1 - len2;
 }
 
@@ -272,6 +274,8 @@ static inline int compare_diacritic_weights(int flags, const WCHAR *str1, int le
         len1--;
         len2--;
     }
+    if (len1 && !*str1) len1--;
+    if (len2 && !*str2) len2--;
     return len1 - len2;
 }
 
@@ -321,23 +325,16 @@ static inline int compare_case_weights(int flags, const WCHAR *str1, int len1,
         len1--;
         len2--;
     }
+    if (len1 && !*str1) len1--;
+    if (len2 && !*str2) len2--;
     return len1 - len2;
 }
 
-static inline int real_length(const WCHAR *str, int len)
-{
-    while (len && !str[len - 1]) len--;
-    return len;
-}
-
 int wine_compare_string(int flags, const WCHAR *str1, int len1,
                         const WCHAR *str2, int len2)
 {
     int ret;
 
-    len1 = real_length(str1, len1);
-    len2 = real_length(str2, len2);
-
     ret = compare_unicode_weights(flags, str1, len1, str2, len2);
     if (!ret)
     {
-- 
2.6.3




More information about the wine-patches mailing list