https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fe9aa42d5f61fdd2fd450…
commit fe9aa42d5f61fdd2fd4501aa7541e09e98207cb7
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Jul 12 17:03:45 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Wed Aug 19 21:39:18 2020 +0200
[CMD] SET: Fix displaying the environment variables with a given prefix.
- Restore any truncated space in the name prefix, before displaying
any error message.
- When trimming the name prefix from "special" characters (spaces, comma
and semicolon), so that e.g. "set ,; ,;FOO" displays all the variables
starting by "FOO", save also a pointer to the original name prefix, that
we will use for variables lookup as well.
This is done, because the SET command allows setting an environment variable
whose name actually contains these characters (e.g. "set ,; ,;FOO=42"),
however, by trimming the characters, doing "set ,; ,;FOO" would not allow
seeing such variables.
With the fix, it is now possible to show them.
---
base/shell/cmd/set.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/base/shell/cmd/set.c b/base/shell/cmd/set.c
index f63de691a2f..0128314ca57 100644
--- a/base/shell/cmd/set.c
+++ b/base/shell/cmd/set.c
@@ -168,12 +168,27 @@ INT cmd_set(LPTSTR param)
else
{
/* Display all the environment variables with the given prefix */
- BOOL bFound = FALSE;
-
+ LPTSTR pOrgParam = param;
+ BOOLEAN bFound = FALSE;
+ BOOLEAN bRestoreSpace;
+
+ /*
+ * Trim the prefix from "special" characters (only when displaying the
+ * environment variables), so that e.g. "SET ,; ,;FOO" will display
all
+ * the variables starting by "FOO".
+ * The SET command allows as well to set an environment variable whose name
+ * actually contains these characters (e.g. "SET ,; ,;FOO=42");
however,
+ * by trimming the characters, doing "SET ,; ,;FOO" would not allow
seeing
+ * such variables.
+ * Thus, we also save a pointer to the original variable name prefix, that
+ * we will look it up as well below.
+ */
while (_istspace(*param) || *param == _T(',') || *param ==
_T(';'))
- param++;
+ ++param;
+ /* Just remove the very last space, if present */
p = _tcsrchr(param, _T(' '));
+ bRestoreSpace = (p != NULL);
if (!p)
p = param + _tcslen(param);
*p = _T('\0');
@@ -184,7 +199,9 @@ INT cmd_set(LPTSTR param)
lpOutput = lpEnv;
while (*lpOutput)
{
- if (!_tcsnicmp(lpOutput, param, p - param))
+ /* Look up for both the original and truncated variable name prefix */
+ if (!_tcsnicmp(lpOutput, pOrgParam, p - pOrgParam) ||
+ !_tcsnicmp(lpOutput, param, p - param))
{
ConOutPuts(lpOutput);
ConOutChar(_T('\n'));
@@ -195,6 +212,11 @@ INT cmd_set(LPTSTR param)
FreeEnvironmentStrings(lpEnv);
}
+ /* Restore the truncated space for correctly
+ * displaying the error message, if any. */
+ if (bRestoreSpace)
+ *p = _T(' ');
+
if (!bFound)
{
ConErrResPrintf(STRING_SET_ENV_ERROR, param);