dll,launcher: invariant string comparisons

This commit is contained in:
Bill Zissimopoulos 2016-12-09 14:23:53 -08:00
parent 228f9e2708
commit 3a65ce332b
5 changed files with 49 additions and 18 deletions

View File

@ -107,7 +107,7 @@ static void fsp_fuse_opt_match_templ(
if ('%' == *p || '\0' == *p) if ('%' == *p || '\0' == *p)
*pspec = p, *parg = q; *pspec = p, *parg = q;
else else
*parg = 0 == lstrcmpA(q, p) ? *parg = 0 == invariant_strcmp(q, p) ?
fsp_fuse_opt_match_exact : fsp_fuse_opt_match_none; fsp_fuse_opt_match_exact : fsp_fuse_opt_match_none;
} }
else else

View File

@ -252,7 +252,7 @@ static WCHAR FspNpGetDriveLetter(PDWORD PLogicalDrives, PWSTR VolumeName)
LocalNameBuf[0] = Drive; LocalNameBuf[0] = Drive;
if (QueryDosDeviceW(LocalNameBuf, VolumeNameBuf, sizeof VolumeNameBuf / sizeof(WCHAR))) if (QueryDosDeviceW(LocalNameBuf, VolumeNameBuf, sizeof VolumeNameBuf / sizeof(WCHAR)))
{ {
if (0 == lstrcmpW(VolumeNameBuf, VolumeName)) if (0 == invariant_wcscmp(VolumeNameBuf, VolumeName))
{ {
*PLogicalDrives &= ~(1 << (Drive - 'A')); *PLogicalDrives &= ~(1 << (Drive - 'A'));
return Drive; return Drive;
@ -432,7 +432,7 @@ DWORD APIENTRY NPGetConnection(
{ {
if (L'\0' == *P) if (L'\0' == *P)
{ {
if (0 == lstrcmpW(VolumeNameBuf, VolumeName)) if (0 == invariant_wcscmp(VolumeNameBuf, VolumeName))
{ {
/* /*
* Looks like this is a WinFsp device. Extract the VolumePrefix from the VolumeName. * Looks like this is a WinFsp device. Extract the VolumePrefix from the VolumeName.
@ -604,7 +604,7 @@ DWORD APIENTRY NPAddConnection(LPNETRESOURCEW lpNetResource, LPWSTR lpPassword,
RemoteNameSize = sizeof RemoteNameBuf / sizeof(WCHAR); RemoteNameSize = sizeof RemoteNameBuf / sizeof(WCHAR);
NpResult = NPGetConnection(LocalNameBuf, RemoteNameBuf, &RemoteNameSize); NpResult = NPGetConnection(LocalNameBuf, RemoteNameBuf, &RemoteNameSize);
if (WN_SUCCESS == NpResult) if (WN_SUCCESS == NpResult)
NpResult = 0 == lstrcmpW(ExpectRemoteNameBuf, RemoteNameBuf) ? WN_SUCCESS : WN_NO_NETWORK; NpResult = 0 == invariant_wcscmp(ExpectRemoteNameBuf, RemoteNameBuf) ? WN_SUCCESS : WN_NO_NETWORK;
else else
NpResult = WN_NO_NETWORK; NpResult = WN_NO_NETWORK;
} }
@ -1036,9 +1036,7 @@ NTSTATUS FspNpRegister(VOID)
{ {
if (L',' == *P || '\0' == *P) if (L',' == *P || '\0' == *P)
{ {
if (CSTR_EQUAL == CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, if (0 == invariant_wcsncmp(Part, L"" FSP_NP_NAME, P - Part))
Part, (int)(P - Part),
L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
{ {
FoundProvider = TRUE; FoundProvider = TRUE;
break; break;
@ -1099,9 +1097,7 @@ NTSTATUS FspNpUnregister(VOID)
{ {
if (L',' == *P || '\0' == *P) if (L',' == *P || '\0' == *P)
{ {
if (CSTR_EQUAL == CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, if (0 == invariant_wcsncmp(Part, L"" FSP_NP_NAME, P - Part))
Part, (int)(P - Part),
L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
{ {
FoundProvider = TRUE; FoundProvider = TRUE;
break; break;

View File

@ -227,7 +227,7 @@ int wmain(int argc, wchar_t **argv)
if (0 == argc) if (0 == argc)
usage(); usage();
if (0 == lstrcmpW(L"start", argv[0])) if (0 == invariant_wcscmp(L"start", argv[0]))
{ {
if (3 > argc || argc > 12) if (3 > argc || argc > 12)
usage(); usage();
@ -236,7 +236,7 @@ int wmain(int argc, wchar_t **argv)
FALSE); FALSE);
} }
else else
if (0 == lstrcmpW(L"startWithSecret", argv[0])) if (0 == invariant_wcscmp(L"startWithSecret", argv[0]))
{ {
if (4 > argc || argc > 13) if (4 > argc || argc > 13)
usage(); usage();
@ -245,7 +245,7 @@ int wmain(int argc, wchar_t **argv)
TRUE); TRUE);
} }
else else
if (0 == lstrcmpW(L"stop", argv[0])) if (0 == invariant_wcscmp(L"stop", argv[0]))
{ {
if (3 != argc) if (3 != argc)
usage(); usage();
@ -253,7 +253,7 @@ int wmain(int argc, wchar_t **argv)
return stop(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2]); return stop(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2]);
} }
else else
if (0 == lstrcmpW(L"info", argv[0])) if (0 == invariant_wcscmp(L"info", argv[0]))
{ {
if (3 != argc) if (3 != argc)
usage(); usage();
@ -261,7 +261,7 @@ int wmain(int argc, wchar_t **argv)
return getinfo(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2]); return getinfo(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE, argv[1], argv[2]);
} }
else else
if (0 == lstrcmpW(L"list", argv[0])) if (0 == invariant_wcscmp(L"list", argv[0]))
{ {
if (1 != argc) if (1 != argc)
usage(); usage();
@ -269,7 +269,7 @@ int wmain(int argc, wchar_t **argv)
return list(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE); return list(PipeBuf, LAUNCHER_PIPE_BUFFER_SIZE);
} }
else else
if (0 == lstrcmpW(L"quit", argv[0])) if (0 == invariant_wcscmp(L"quit", argv[0]))
{ {
if (1 != argc) if (1 != argc)
usage(); usage();

View File

@ -157,8 +157,8 @@ static SVC_INSTANCE *SvcInstanceLookup(PWSTR ClassName, PWSTR InstanceName)
{ {
SvcInstance = CONTAINING_RECORD(ListEntry, SVC_INSTANCE, ListEntry); SvcInstance = CONTAINING_RECORD(ListEntry, SVC_INSTANCE, ListEntry);
if (0 == lstrcmpiW(ClassName, SvcInstance->ClassName) && if (0 == invariant_wcsicmp(ClassName, SvcInstance->ClassName) &&
0 == lstrcmpiW(InstanceName, SvcInstance->InstanceName)) 0 == invariant_wcsicmp(InstanceName, SvcInstance->InstanceName))
return SvcInstance; return SvcInstance;
} }

View File

@ -87,6 +87,41 @@ void *memmove(void *dst, const void *src, size_t siz)
return dst; return dst;
} }
#define WINFSP_SHARED_MINIMAL_STRCMP(NAME, TYPE, CONV)\
static inline\
int NAME(const TYPE *s, const TYPE *t)\
{\
int v = 0;\
while (0 == (v = CONV(*s) - CONV(*t)) && *t)\
++s, ++t;\
return v;/*(0 < v) - (0 > v);*/\
}
#define WINFSP_SHARED_MINIMAL_STRNCMP(NAME, TYPE, CONV)\
static inline\
int NAME(const TYPE *s, const TYPE *t, size_t n)\
{\
int v = 0;\
const void *e = t + n;\
while (e > (const void *)t && 0 == (v = CONV(*s) - CONV(*t)) && *t)\
++s, ++t;\
return v;/*(0 < v) - (0 > v);*/\
}
static inline
unsigned invariant_toupper(unsigned c)
{
return ('a' <= c && c <= 'z') ? c & ~0x20 : c;
}
WINFSP_SHARED_MINIMAL_STRCMP(invariant_strcmp, char, (unsigned))
WINFSP_SHARED_MINIMAL_STRCMP(invariant_stricmp, char, invariant_toupper)
WINFSP_SHARED_MINIMAL_STRNCMP(invariant_strncmp, char, (unsigned))
WINFSP_SHARED_MINIMAL_STRNCMP(invariant_strnicmp, char, invariant_toupper)
WINFSP_SHARED_MINIMAL_STRCMP(invariant_wcscmp, wchar_t, (unsigned))
WINFSP_SHARED_MINIMAL_STRCMP(invariant_wcsicmp, wchar_t, invariant_toupper)
WINFSP_SHARED_MINIMAL_STRNCMP(invariant_wcsncmp, wchar_t, (unsigned))
WINFSP_SHARED_MINIMAL_STRNCMP(invariant_wcsnicmp, wchar_t, invariant_toupper)
#undef WINFSP_SHARED_MINIMAL_STRCMP
#undef WINFSP_SHARED_MINIMAL_STRNCMP
static inline void *MemAlloc(size_t Size) static inline void *MemAlloc(size_t Size)
{ {
return HeapAlloc(GetProcessHeap(), 0, Size); return HeapAlloc(GetProcessHeap(), 0, Size);