https://git.reactos.org/?p=reactos.git;a=commitdiff;h=495c82ccde712acb9f59456ddc6cbfea5e4c9199

commit 495c82ccde712acb9f59456ddc6cbfea5e4c9199
Author:     Hermès Bélusca-Maïto <[email protected]>
AuthorDate: Mon May 18 02:16:40 2020 +0200
Commit:     Hermès Bélusca-Maïto <[email protected]>
CommitDate: Wed Aug 19 20:35:59 2020 +0200

    [CMD] Syntax errors during parsing of batch parameters expansion, or FOR 
and IF commands, are fatal, and batch execution should stop.
    
    - To this purpose use the ParseErrorEx() that correctly sets the
      bParseError flag, and return the partially-parsed command so that
      it gets echoed as well for diagnostics purposes (Windows-compatible).
    
    - Any other parameters specified after (or before) the '/?' switch for
      the FOR and IF commands, are considered fatal syntax errors as well,
      thus we employ the ParseErrorEx() as well.
---
 base/shell/cmd/cmd.c | 10 +++++++++-
 base/shell/cmd/for.c |  2 +-
 base/shell/cmd/if.c  |  2 +-
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c
index 97f346af852..31910e9e2ef 100644
--- a/base/shell/cmd/cmd.c
+++ b/base/shell/cmd/cmd.c
@@ -1208,7 +1208,7 @@ GetBatchVar(TCHAR *varName, UINT *varNameLen)
         ret = GetEnhancedVar(&varNameEnd, FindArg);
         if (!ret)
         {
-            error_syntax(varName);
+            ParseErrorEx(varName);
             return NULL;
         }
         *varNameLen = varNameEnd - varName;
@@ -1267,6 +1267,14 @@ SubstituteVars(TCHAR *Src, TCHAR *Dest, TCHAR Delim)
         {
             UINT NameLen;
             Var = GetBatchVar(Src, &NameLen);
+            if (!Var && bParseError)
+            {
+                /* Return the partially-parsed command to be
+                 * echoed for error diagnostics purposes. */
+                APPEND1(Delim);
+                APPEND(Src, DestEnd-Dest);
+                return FALSE;
+            }
             if (Var != NULL)
             {
                 VarLength = _tcslen(Var);
diff --git a/base/shell/cmd/for.c b/base/shell/cmd/for.c
index 744d740b948..75b462352cf 100644
--- a/base/shell/cmd/for.c
+++ b/base/shell/cmd/for.c
@@ -44,7 +44,7 @@ INT cmd_for(LPTSTR param)
         return 0;
     }
 
-    error_syntax(param);
+    ParseErrorEx(param);
     return 1;
 }
 
diff --git a/base/shell/cmd/if.c b/base/shell/cmd/if.c
index 26f56dee95a..830ec459c8a 100644
--- a/base/shell/cmd/if.c
+++ b/base/shell/cmd/if.c
@@ -59,7 +59,7 @@ INT cmd_if(LPTSTR param)
         return 0;
     }
 
-    error_syntax(param);
+    ParseErrorEx(param);
     return 1;
 }
 

Reply via email to