ReactOS  0.4.14-dev-50-g13bb5e2
RtlComputePrivatizedDllName_U.c File Reference
#include "precomp.h"
Include dependency graph for RtlComputePrivatizedDllName_U.c:

Go to the source code of this file.

Macros

#define ok_strings(Real, Local, Dll)   ok_strings_(Real, Local, Dll, __LINE__)
 

Functions

static BOOL InitTestData ()
 
static void ok_strings_ (PCUNICODE_STRING RealName, PCUNICODE_STRING LocalName, LPCWSTR DllName, int line)
 
static void cleanup (PUNICODE_STRING String, WCHAR *Buffer, USHORT BufferSize)
 
static void test_dllnames (void)
 
static void test_allocations (void)
 
 START_TEST (RtlComputePrivatizedDllName_U)
 

Variables

static WCHAR ProcessDir [MAX_PATH]
 
static WCHAR LocalDir [MAX_PATH+10]
 

Macro Definition Documentation

◆ ok_strings

#define ok_strings (   Real,
  Local,
  Dll 
)    ok_strings_(Real, Local, Dll, __LINE__)

Definition at line 64 of file RtlComputePrivatizedDllName_U.c.

Function Documentation

◆ cleanup()

static void cleanup ( PUNICODE_STRING  String,
WCHAR Buffer,
USHORT  BufferSize 
)
static

Definition at line 67 of file RtlComputePrivatizedDllName_U.c.

68 {
69  if (String->Buffer != Buffer)
70  {
72  RtlInitEmptyUnicodeString(String, Buffer, BufferSize);
73  }
74 }
static WCHAR String[]
Definition: stringtable.c:55
Definition: bufpool.h:45
#define BufferSize
Definition: classpnp.h:419
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)

Referenced by test_allocations(), and test_dllnames().

◆ InitTestData()

static BOOL InitTestData ( )
static

Definition at line 14 of file RtlComputePrivatizedDllName_U.c.

15 {
16  static const UNICODE_STRING PathDividerFind = RTL_CONSTANT_STRING(L"\\/");
17  UNICODE_STRING StrU;
18  USHORT PathDivider;
19 
22 
24 
25  if (!NT_SUCCESS(RtlFindCharInUnicodeString(RTL_FIND_CHAR_IN_UNICODE_STRING_START_AT_END,
26  &StrU, &PathDividerFind, &PathDivider)))
27  {
28  skip("Failed to find path divider\n");
29  return FALSE;
30  }
31  ProcessDir[PathDivider / sizeof(WCHAR) + 1] = UNICODE_NULL;
32 
34  StrU.MaximumLength = sizeof(LocalDir);
35 
36  if (!NT_SUCCESS(RtlAppendUnicodeToString(&StrU, L".Local\\")))
37  {
38  skip("Failed to append .Local\\\n");
39  return FALSE;
40  }
41  return TRUE;
42 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:609
#define TRUE
Definition: types.h:120
USHORT MaximumLength
Definition: env_spec_w32.h:370
static WCHAR LocalDir[MAX_PATH+10]
#define UNICODE_NULL
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static WCHAR ProcessDir[MAX_PATH]
static const WCHAR L[]
Definition: oid.c:1250
unsigned short USHORT
Definition: pedump.c:61
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define skip(...)
Definition: atltest.h:64
NTSYSAPI NTSTATUS NTAPI RtlFindCharInUnicodeString(_In_ ULONG Flags, _In_ PCUNICODE_STRING SearchString, _In_ PCUNICODE_STRING MatchString, _Out_ PUSHORT Position)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by START_TEST().

◆ ok_strings_()

static void ok_strings_ ( PCUNICODE_STRING  RealName,
PCUNICODE_STRING  LocalName,
LPCWSTR  DllName,
int  line 
)
static

Definition at line 44 of file RtlComputePrivatizedDllName_U.c.

45 {
46  WCHAR ExpectReal[MAX_PATH*2];
47  WCHAR ExpectLocal[MAX_PATH*2];
48  int RealLen;
49  int ExpectLen;
50 
51  RealLen = swprintf(ExpectReal, L"%s%s", ProcessDir, DllName) * sizeof(WCHAR);
52  ExpectLen = swprintf(ExpectLocal, L"%s%s", LocalDir, DllName) * sizeof(WCHAR);
53 
54  ok_(__FILE__, line)(RealLen == RealName->Length, "Expected Real %u, got %u\n",
55  (UINT)RealLen, (UINT)RealName->Length);
56  ok_(__FILE__, line)(ExpectLen == LocalName->Length, "Expected Local %u, got %u\n",
57  (UINT)ExpectLen, (UINT)LocalName->Length);
58 
59  ok_(__FILE__, line)(!wcscmp(RealName->Buffer, ExpectReal), "Expected Real %s, got %s\n",
60  wine_dbgstr_w(ExpectReal), wine_dbgstr_w(RealName->Buffer));
61  ok_(__FILE__, line)(!wcscmp(LocalName->Buffer, ExpectLocal), "Expected Local %s, got %s\n",
62  wine_dbgstr_w(ExpectLocal), wine_dbgstr_w(LocalName->Buffer));
63 }
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
static WCHAR LocalDir[MAX_PATH+10]
Definition: parser.c:48
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
#define swprintf(buf, format,...)
Definition: sprintf.c:56
static WCHAR ProcessDir[MAX_PATH]
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
unsigned int UINT
Definition: ndis.h:50
#define ok_(x1, x2)
Definition: atltest.h:61

◆ START_TEST()

Definition at line 229 of file RtlComputePrivatizedDllName_U.c.

230 {
231  if (!InitTestData())
232  return;
233 
234  test_dllnames();
236 }
static void test_allocations(void)
static BOOL InitTestData()
static void test_dllnames(void)

◆ test_allocations()

static void test_allocations ( void  )
static

Definition at line 206 of file RtlComputePrivatizedDllName_U.c.

207 {
208  WCHAR Buf1[10];
209  WCHAR Buf2[10];
210 
211  UNICODE_STRING Str1, Str2;
212  UNICODE_STRING DllName;
214 
215  RtlInitEmptyUnicodeString(&Str1, Buf1, sizeof(Buf1));
216  RtlInitEmptyUnicodeString(&Str2, Buf2, sizeof(Buf2));
217 
218  RtlInitUnicodeString(&DllName, L"kernel32.dll");
219  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
220  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
221  ok_strings(&Str1, &Str2, L"kernel32.dll");
222  ok(Str1.Buffer != Buf1, "Expected a changed buffer\n");
223  ok(Str2.Buffer != Buf2, "Expected a changed buffer\n");
224  cleanup(&Str1, Buf1, sizeof(Buf1));
225  cleanup(&Str2, Buf2, sizeof(Buf2));
226 }
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlComputePrivatizedDllName_U(_In_ PUNICODE_STRING DllName, _Inout_ PUNICODE_STRING RealName, _Inout_ PUNICODE_STRING LocalName)
Definition: path.c:467
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ok_strings(Real, Local, Dll)
static const WCHAR L[]
Definition: oid.c:1250
static void cleanup(PUNICODE_STRING String, WCHAR *Buffer, USHORT BufferSize)
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by START_TEST().

◆ test_dllnames()

static void test_dllnames ( void  )
static

Definition at line 77 of file RtlComputePrivatizedDllName_U.c.

78 {
79  WCHAR Buf1[MAX_PATH];
80  WCHAR Buf2[MAX_PATH];
81 
82  UNICODE_STRING Str1, Str2;
83  UNICODE_STRING DllName;
85 
86  RtlInitEmptyUnicodeString(&Str1, Buf1, sizeof(Buf1));
87  RtlInitEmptyUnicodeString(&Str2, Buf2, sizeof(Buf2));
88 
89  RtlInitUnicodeString(&DllName, L"kernel32.dll");
90  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
91  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
92  ok_strings(&Str1, &Str2, L"kernel32.dll");
93  cleanup(&Str1, Buf1, sizeof(Buf1));
94  cleanup(&Str2, Buf2, sizeof(Buf2));
95 
96 
97  RtlInitUnicodeString(&DllName, L"kernel32");
98  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
99  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
100  ok_strings(&Str1, &Str2, L"kernel32.DLL");
101  cleanup(&Str1, Buf1, sizeof(Buf1));
102  cleanup(&Str2, Buf2, sizeof(Buf2));
103 
104  RtlInitUnicodeString(&DllName, L"kernel32.dll.dll");
105  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
106  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
107  ok_strings(&Str1, &Str2, L"kernel32.dll.dll");
108  cleanup(&Str1, Buf1, sizeof(Buf1));
109  cleanup(&Str2, Buf2, sizeof(Buf2));
110 
111  RtlInitUnicodeString(&DllName, L"kernel32.dll.exe");
112  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
113  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
114  ok_strings(&Str1, &Str2, L"kernel32.dll.exe");
115  cleanup(&Str1, Buf1, sizeof(Buf1));
116  cleanup(&Str2, Buf2, sizeof(Buf2));
117 
118  RtlInitUnicodeString(&DllName, L"kernel32.");
119  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
120  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
121  ok_strings(&Str1, &Str2, L"kernel32.");
122  cleanup(&Str1, Buf1, sizeof(Buf1));
123  cleanup(&Str2, Buf2, sizeof(Buf2));
124 
125  RtlInitUnicodeString(&DllName, L".kernel32");
126  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
127  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
128  ok_strings(&Str1, &Str2, L".kernel32.DLL");
129  cleanup(&Str1, Buf1, sizeof(Buf1));
130  cleanup(&Str2, Buf2, sizeof(Buf2));
131 
132  RtlInitUnicodeString(&DllName, L"..kernel32");
133  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
134  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
135  ok_strings(&Str1, &Str2, L"..kernel32");
136  cleanup(&Str1, Buf1, sizeof(Buf1));
137  cleanup(&Str2, Buf2, sizeof(Buf2));
138 
139  RtlInitUnicodeString(&DllName, L".kernel32.");
140  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
141  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
142  ok_strings(&Str1, &Str2, L".kernel32.");
143  cleanup(&Str1, Buf1, sizeof(Buf1));
144  cleanup(&Str2, Buf2, sizeof(Buf2));
145 
146 
147  RtlInitUnicodeString(&DllName, L"test\\kernel32.dll");
148  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
149  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
150  ok_strings(&Str1, &Str2, L"kernel32.dll");
151  cleanup(&Str1, Buf1, sizeof(Buf1));
152  cleanup(&Str2, Buf2, sizeof(Buf2));
153 
154  RtlInitUnicodeString(&DllName, L"test/kernel32.dll");
155  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
156  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
157  ok_strings(&Str1, &Str2, L"kernel32.dll");
158  cleanup(&Str1, Buf1, sizeof(Buf1));
159  cleanup(&Str2, Buf2, sizeof(Buf2));
160 
161  RtlInitUnicodeString(&DllName, L"test.dll/kernel32");
162  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
163  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
164  ok_strings(&Str1, &Str2, L"kernel32.DLL");
165  cleanup(&Str1, Buf1, sizeof(Buf1));
166  cleanup(&Str2, Buf2, sizeof(Buf2));
167 
168  RtlInitUnicodeString(&DllName, L"test.dll\\kernel32");
169  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
170  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
171  ok_strings(&Str1, &Str2, L"kernel32.DLL");
172  cleanup(&Str1, Buf1, sizeof(Buf1));
173  cleanup(&Str2, Buf2, sizeof(Buf2));
174 
175  RtlInitUnicodeString(&DllName, L"//");
176  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
177  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
178  ok_strings(&Str1, &Str2, L".DLL");
179  cleanup(&Str1, Buf1, sizeof(Buf1));
180  cleanup(&Str2, Buf2, sizeof(Buf2));
181 
182  // Bug :)
183  RtlInitUnicodeString(&DllName, L"\\");
184  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
185  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
186  if (wcsstr(Str1.Buffer, L"\\\\"))
187  {
188  trace("Allowing bug found in windows' implementation\n");
189  ok_strings(&Str1, &Str2, L"\\.DLL");
190  }
191  else
192  {
193  ok_strings(&Str1, &Str2, L".DLL");
194  }
195  cleanup(&Str1, Buf1, sizeof(Buf1));
196  cleanup(&Str2, Buf2, sizeof(Buf2));
197 
198  RtlInitUnicodeString(&DllName, L"");
199  Status = RtlComputePrivatizedDllName_U(&DllName, &Str1, &Str2);
200  ok(Status == STATUS_SUCCESS, "0x%lx\n", Status);
201  ok_strings(&Str1, &Str2, L".DLL");
202  cleanup(&Str1, Buf1, sizeof(Buf1));
203  cleanup(&Str2, Buf2, sizeof(Buf2));
204 }
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI NTSTATUS NTAPI RtlComputePrivatizedDllName_U(_In_ PUNICODE_STRING DllName, _Inout_ PUNICODE_STRING RealName, _Inout_ PUNICODE_STRING LocalName)
Definition: path.c:467
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ok_strings(Real, Local, Dll)
#define MAX_PATH
Definition: compat.h:26
static const WCHAR L[]
Definition: oid.c:1250
static void cleanup(PUNICODE_STRING String, WCHAR *Buffer, USHORT BufferSize)
Status
Definition: gdiplustypes.h:24
#define ok(value,...)
Definition: atltest.h:57
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by START_TEST().

Variable Documentation

◆ LocalDir

WCHAR LocalDir[MAX_PATH+10]
static

Definition at line 12 of file RtlComputePrivatizedDllName_U.c.

Referenced by InitTestData(), and ok_strings_().

◆ ProcessDir

WCHAR ProcessDir[MAX_PATH]
static

Definition at line 11 of file RtlComputePrivatizedDllName_U.c.

Referenced by InitTestData(), and ok_strings_().