Alexandre Julliard : ntdll: Use the ascii_to_unicode() helper to compare relay module names.

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


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

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

ntdll: Use the ascii_to_unicode() helper to compare relay module names.

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

---

 dlls/ntdll/loader.c     |  6 ------
 dlls/ntdll/ntdll_misc.h |  6 ++++++
 dlls/ntdll/relay.c      | 28 +++++++++++++---------------
 3 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index fbbd29a595..8f607409f5 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -185,12 +185,6 @@ static inline BOOL contains_path( LPCWSTR name )
     return ((*name && (name[1] == ':')) || strchrW(name, '/') || strchrW(name, '\\'));
 }
 
-/* convert from straight ASCII to Unicode without depending on the current codepage */
-static inline void ascii_to_unicode( WCHAR *dst, const char *src, size_t len )
-{
-    while (len--) *dst++ = (unsigned char)*src++;
-}
-
 #define RTL_UNLOAD_EVENT_TRACE_NUMBER 64
 
 typedef struct _RTL_UNLOAD_EVENT_TRACE
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 45ca35442f..953b29dfe5 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -299,4 +299,10 @@ ULONG  __cdecl NTDLL_wcstoul( LPCWSTR s, LPWSTR *end, INT base );
 #define wcsicmp(s1,s2) NTDLL__wcsicmp(s1,s2)
 #define wcsnicmp(s1,s2,n) NTDLL__wcsnicmp(s1,s2,n)
 
+/* convert from straight ASCII to Unicode without depending on the current codepage */
+static inline void ascii_to_unicode( WCHAR *dst, const char *src, size_t len )
+{
+    while (len--) *dst++ = (unsigned char)*src++;
+}
+
 #endif
diff --git a/dlls/ntdll/relay.c b/dlls/ntdll/relay.c
index 9ebb973e9a..b4ea0a4dba 100644
--- a/dlls/ntdll/relay.c
+++ b/dlls/ntdll/relay.c
@@ -93,15 +93,6 @@ static inline int strcmpAW( const char *strA, const WCHAR *strW )
     return (unsigned char)*strA - *strW;
 }
 
-/* compare an ASCII and a Unicode string without depending on the current codepage */
-static inline int strncmpiAW( const char *strA, const WCHAR *strW, int n )
-{
-    int ret = 0;
-    for ( ; n > 0; n--, strA++, strW++)
-        if ((ret = toupperW((unsigned char)*strA) - toupperW(*strW)) || !*strA) break;
-    return ret;
-}
-
 /***********************************************************************
  *           build_list
  *
@@ -225,7 +216,7 @@ static DWORD WINAPI init_debug_lists( RTL_RUN_ONCE *once, void *param, void **co
  *
  * Check if a given module and function is in the list.
  */
-static BOOL check_list( const char *module, int ordinal, const char *func, const WCHAR *const *list )
+static BOOL check_list( const WCHAR *module, int ordinal, const char *func, const WCHAR *const *list )
 {
     char ord_str[10];
 
@@ -236,7 +227,7 @@ static BOOL check_list( const char *module, int ordinal, const char *func, const
         if (p && p > *list)  /* check module and function */
         {
             int len = p - *list;
-            if (strncmpiAW( module, *list, len-1 ) || module[len]) continue;
+            if (wcsnicmp( module, *list, len - 1 ) || module[len]) continue;
             if (p[1] == '*' && !p[2]) return TRUE;
             if (!strcmpAW( ord_str, p + 1 )) return TRUE;
             if (func && !strcmpAW( func, p + 1 )) return TRUE;
@@ -255,7 +246,7 @@ static BOOL check_list( const char *module, int ordinal, const char *func, const
  *
  * Check if a given function must be included in the relay output.
  */
-static BOOL check_relay_include( const char *module, int ordinal, const char *func )
+static BOOL check_relay_include( const WCHAR *module, int ordinal, const char *func )
 {
     if (debug_relay_excludelist && check_list( module, ordinal, func, debug_relay_excludelist ))
         return FALSE;
@@ -898,6 +889,7 @@ void RELAY_SetupDLL( HMODULE module )
     DWORD size, entry_point_rva, old_prot;
     struct relay_descr *descr;
     struct relay_private_data *data;
+    WCHAR dllnameW[sizeof(data->dllname)];
     const WORD *ordptr;
     void *func_base;
     SIZE_T func_size;
@@ -923,6 +915,7 @@ void RELAY_SetupDLL( HMODULE module )
     len = min( len, sizeof(data->dllname) - 1 );
     memcpy( data->dllname, (char *)module + exports->Name, len );
     data->dllname[len] = 0;
+    ascii_to_unicode( dllnameW, data->dllname, len + 1 );
 
     /* fetch name pointer for all entry points and store them in the private structure */
 
@@ -944,7 +937,7 @@ void RELAY_SetupDLL( HMODULE module )
     for (i = 0; i < exports->NumberOfFunctions; i++, funcs++)
     {
         if (!descr->entry_point_offsets[i]) continue;   /* not a normal function */
-        if (!check_relay_include( data->dllname, i + exports->Base, data->entry_points[i].name ))
+        if (!check_relay_include( dllnameW, i + exports->Base, data->entry_points[i].name ))
             continue;  /* don't include this entry point */
 
         data->entry_points[i].orig_func = (char *)module + *funcs;
@@ -1035,9 +1028,14 @@ static SNOOP_RETURNENTRIES *firstrets;
  */
 static BOOL SNOOP_ShowDebugmsgSnoop(const char *module, int ordinal, const char *func)
 {
-    if (debug_snoop_excludelist && check_list( module, ordinal, func, debug_snoop_excludelist ))
+    WCHAR moduleW[40];
+    int len = strlen(module);
+
+    if (len >= ARRAY_SIZE( moduleW )) return FALSE;
+    ascii_to_unicode( moduleW, module, len + 1 );
+    if (debug_snoop_excludelist && check_list( moduleW, ordinal, func, debug_snoop_excludelist ))
         return FALSE;
-    if (debug_snoop_includelist && !check_list( module, ordinal, func, debug_snoop_includelist ))
+    if (debug_snoop_includelist && !check_list( moduleW, ordinal, func, debug_snoop_includelist ))
         return FALSE;
     return TRUE;
 }




More information about the wine-cvs mailing list