Alexandre Julliard : ntdll: Use RtlCompareUnicodeStrings() instead of strncmpiW().

Alexandre Julliard julliard at winehq.org
Fri Mar 27 16:14:38 CDT 2020


Module: wine
Branch: master
Commit: 2f7cc584ce09448e8f5434191210f0d217b2e437
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=2f7cc584ce09448e8f5434191210f0d217b2e437

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Mar 27 13:39:44 2020 +0100

ntdll: Use RtlCompareUnicodeStrings() instead of strncmpiW().

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/directory.c |  6 +++---
 dlls/ntdll/env.c       | 18 ++++++++++++------
 dlls/ntdll/loader.c    |  8 +++++---
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c
index c3da7347d7..53da0b0fc8 100644
--- a/dlls/ntdll/directory.c
+++ b/dlls/ntdll/directory.c
@@ -2102,7 +2102,7 @@ static NTSTATUS find_file_in_dir( char *unix_name, int pos, const WCHAR *name, i
                     {
                         ret = ntdll_umbstowcs( kde[1].d_name, strlen(kde[1].d_name),
                                                buffer, MAX_DIR_ENTRY_LEN );
-                        if (ret == length && !strncmpiW( buffer, name, length))
+                        if (ret == length && !RtlCompareUnicodeStrings( buffer, ret, name, ret, TRUE ))
                         {
                             strcpy( unix_name + pos, kde[1].d_name );
                             RtlLeaveCriticalSection( &dir_section );
@@ -2112,7 +2112,7 @@ static NTSTATUS find_file_in_dir( char *unix_name, int pos, const WCHAR *name, i
                     }
                     ret = ntdll_umbstowcs( kde[0].d_name, strlen(kde[0].d_name),
                                            buffer, MAX_DIR_ENTRY_LEN );
-                    if (ret == length && !strncmpiW( buffer, name, length))
+                    if (ret == length && !RtlCompareUnicodeStrings( buffer, ret, name, ret, TRUE ))
                     {
                         strcpy( unix_name + pos,
                                 kde[1].d_name[0] ? kde[1].d_name : kde[0].d_name );
@@ -2146,7 +2146,7 @@ static NTSTATUS find_file_in_dir( char *unix_name, int pos, const WCHAR *name, i
     while ((de = readdir( dir )))
     {
         ret = ntdll_umbstowcs( de->d_name, strlen(de->d_name), buffer, MAX_DIR_ENTRY_LEN );
-        if (ret == length && !strncmpiW( buffer, name, length ))
+        if (ret == length && !RtlCompareUnicodeStrings( buffer, ret, name, ret, TRUE ))
         {
             strcpy( unix_name + pos, de->d_name );
             closedir( dir );
diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c
index c8098e2d59..833da58f35 100644
--- a/dlls/ntdll/env.c
+++ b/dlls/ntdll/env.c
@@ -903,16 +903,20 @@ NTSTATUS WINAPI RtlDestroyEnvironment(PWSTR env)
 
 static LPCWSTR ENV_FindVariable(PCWSTR var, PCWSTR name, unsigned namelen)
 {
-    for (; *var; var += strlenW(var) + 1)
+    while (*var)
     {
         /* match var names, but avoid setting a var with a name including a '='
          * (a starting '=' is valid though)
          */
-        if (strncmpiW(var, name, namelen) == 0 && var[namelen] == '=' &&
-            strchrW(var + 1, '=') == var + namelen) 
+        unsigned int len = strlenW( var );
+        if (len > namelen &&
+            var[namelen] == '=' &&
+            !RtlCompareUnicodeStrings( var, namelen, name, namelen, TRUE ) &&
+            strchrW(var + 1, '=') == var + namelen)
         {
             return var + namelen + 1;
         }
+        var += len + 1;
     }
     return NULL;
 }
@@ -987,7 +991,7 @@ void WINAPI RtlSetCurrentEnvironment(PWSTR new_env, PWSTR* old_env)
 NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name, 
                                           PUNICODE_STRING value)
 {
-    INT         len, old_size;
+    INT varlen, len, old_size;
     LPWSTR      p, env;
     NTSTATUS    nts = STATUS_VARIABLE_NOT_FOUND;
 
@@ -1011,9 +1015,11 @@ NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name,
     old_size = get_env_length( env );
 
     /* Find a place to insert the string */
-    for (p = env; *p; p += strlenW(p) + 1)
+    for (p = env; *p; p += varlen + 1)
     {
-        if (!strncmpiW(name->Buffer, p, len) && (p[len] == '=')) break;
+        varlen = strlenW(p);
+        if (varlen > len && p[len] == '=' &&
+            !RtlCompareUnicodeStrings( name->Buffer, len, p, len, TRUE )) break;
     }
     if (!value && !*p) goto done;  /* Value to remove doesn't exist */
 
diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index 735a7d21fc..fbbd29a595 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -2768,10 +2768,12 @@ static NTSTATUS find_actctx_dll( LPCWSTR libname, LPWSTR *fullname )
 
     if ((p = strrchrW( info->lpAssemblyManifestPath, '\\' )))
     {
-        DWORD dirlen = info->ulAssemblyDirectoryNameLength / sizeof(WCHAR);
-
+        DWORD len, dirlen = info->ulAssemblyDirectoryNameLength / sizeof(WCHAR);
         p++;
-        if (!dirlen || strncmpiW( p, info->lpAssemblyDirectoryName, dirlen ) || wcsicmp( p + dirlen, dotManifestW ))
+        len = strlenW( p );
+        if (!dirlen || len <= dirlen ||
+            RtlCompareUnicodeStrings( p, dirlen, info->lpAssemblyDirectoryName, dirlen, TRUE ) ||
+            wcsicmp( p + dirlen, dotManifestW ))
         {
             /* manifest name does not match directory name, so it's not a global
              * windows/winsxs manifest; use the manifest directory name instead */




More information about the wine-cvs mailing list