https://git.reactos.org/?p=reactos.git;a=commitdiff;h=41a93a4e58d3aa62ae3e28303e8433878169d827

commit 41a93a4e58d3aa62ae3e28303e8433878169d827
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Sun Jul 12 23:07:23 2020 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Wed Aug 19 20:36:11 2020 +0200

    [CMD] FOR: Some functionality is available only when extensions are enabled.
    
    This is basically all the advanced functionality enabled with the /D,
    /R, /L and /F flags, and the usage of enhanced variables.
---
 base/shell/cmd/for.c    | 32 ++++++++++++++++++++------------
 base/shell/cmd/parser.c |  6 ++++++
 2 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/base/shell/cmd/for.c b/base/shell/cmd/for.c
index 75b462352cf..67a9240c787 100644
--- a/base/shell/cmd/for.c
+++ b/base/shell/cmd/for.c
@@ -500,19 +500,27 @@ ExecuteFor(PARSED_COMMAND *Cmd)
     Cmd->For.Context = lpNew;
     fc = lpNew;
 
-    if (Cmd->For.Switches & FOR_F)
+    /* Run the extended FOR syntax only if extensions are enabled */
+    if (bEnableExtensions)
     {
-        Ret = ForF(Cmd, List, Buffer);
-    }
-    else if (Cmd->For.Switches & FOR_LOOP)
-    {
-        Ret = ForLoop(Cmd, List, Buffer);
-    }
-    else if (Cmd->For.Switches & FOR_RECURSIVE)
-    {
-        DWORD Len = GetFullPathName(Cmd->For.Params ? Cmd->For.Params : 
_T("."),
-                                    MAX_PATH, Buffer, NULL);
-        Ret = ForRecursive(Cmd, List, Buffer, &Buffer[Len]);
+        if (Cmd->For.Switches & FOR_F)
+        {
+            Ret = ForF(Cmd, List, Buffer);
+        }
+        else if (Cmd->For.Switches & FOR_LOOP)
+        {
+            Ret = ForLoop(Cmd, List, Buffer);
+        }
+        else if (Cmd->For.Switches & FOR_RECURSIVE)
+        {
+            DWORD Len = GetFullPathName(Cmd->For.Params ? Cmd->For.Params : 
_T("."),
+                                        MAX_PATH, Buffer, NULL);
+            Ret = ForRecursive(Cmd, List, Buffer, &Buffer[Len]);
+        }
+        else
+        {
+            Ret = ForDir(Cmd, List, Buffer, Buffer);
+        }
     }
     else
     {
diff --git a/base/shell/cmd/parser.c b/base/shell/cmd/parser.c
index 21bfd2504a9..048c83e3f96 100644
--- a/base/shell/cmd/parser.c
+++ b/base/shell/cmd/parser.c
@@ -494,6 +494,10 @@ static PARSED_COMMAND *ParseFor(void)
     memset(Cmd, 0, sizeof(PARSED_COMMAND));
     Cmd->Type = C_FOR;
 
+    /* Skip the extended FOR syntax if extensions are disabled */
+    if (!bEnableExtensions)
+        goto parseForBody;
+
     while (1)
     {
         if (_tcsicmp(CurrentToken, _T("/D")) == 0)
@@ -543,6 +547,8 @@ static PARSED_COMMAND *ParseFor(void)
         goto error;
     }
 
+parseForBody:
+
     /* Variable name should be % and just one other character */
     if (CurrentToken[0] != _T('%') || _tcslen(CurrentToken) != 2)
         goto error;

Reply via email to