[CMD] Use kernel32!lstrcmp(i) when comparing strings with the IF command.

Use kernel32!lstrcmp(i) instead of CRT!_tcs(i)cmp, so as to use the correct
current thread locale information when comparing user-specific strings.
As a result, the following comparison: 'b LSS B' will return TRUE,
instead of FALSE as it would be by using the CRT functions (and by
naively considering the lexicographical order in ANSI).
This behaviour has been introduced in Windows 2000 onwards.
This commit is contained in:
Hermès Bélusca-Maïto 2020-07-01 02:42:04 +02:00
parent 5830ccb85e
commit 6e09a6a3ff
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0

View file

@ -32,7 +32,7 @@
#include "precomp.h"
static INT GenericCmp(INT (*StringCmp)(LPCTSTR, LPCTSTR),
static INT GenericCmp(INT (WINAPI *StringCmp)(LPCTSTR, LPCTSTR),
LPCTSTR Left, LPCTSTR Right)
{
TCHAR *end;
@ -152,14 +152,20 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
}
else
{
/* Do case-insensitive string comparisons if /I specified */
INT (*StringCmp)(LPCTSTR, LPCTSTR) =
(Cmd->If.Flags & IFFLAG_IGNORECASE) ? _tcsicmp : _tcscmp;
/*
* Do case-insensitive string comparisons if /I specified.
*
* Since both strings are user-specific, use kernel32!lstrcmp(i)
* instead of CRT!_tcs(i)cmp, so as to use the correct
* current thread locale information.
*/
INT (WINAPI *StringCmp)(LPCTSTR, LPCTSTR) =
(Cmd->If.Flags & IFFLAG_IGNORECASE) ? lstrcmpi : lstrcmp;
if (Cmd->If.Operator == IF_STRINGEQ)
{
/* IF str1 == str2 */
result = StringCmp(Left, Right) == 0;
result = (StringCmp(Left, Right) == 0);
}
else
{
@ -168,9 +174,9 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
{
case IF_EQU: result = (result == 0); break;
case IF_NEQ: result = (result != 0); break;
case IF_LSS: result = (result < 0); break;
case IF_LSS: result = (result < 0); break;
case IF_LEQ: result = (result <= 0); break;
case IF_GTR: result = (result > 0); break;
case IF_GTR: result = (result > 0); break;
case IF_GEQ: result = (result >= 0); break;
}
}