https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6e09a6a3ffd92c565e206…
commit 6e09a6a3ffd92c565e20664a023add74eaa55ecf
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Wed Jul 1 02:42:04 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Aug 19 20:36:05 2020 +0200
[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.
---
base/shell/cmd/if.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/base/shell/cmd/if.c b/base/shell/cmd/if.c
index 830ec459c8a..c7882ad2fec 100644
--- a/base/shell/cmd/if.c
+++ b/base/shell/cmd/if.c
@@ -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;
}
}