Skip to content

Commit 1623c1d

Browse files
committed
[gh-11363] Use temp file to capture Java parser output safely
Using 'for /f' to capture output with pipes causes the pipes to be interpreted as command separators. Instead, write to a temp file and read with 'set /p' which doesn't interpret special characters.
1 parent 6a37bff commit 1623c1d

File tree

1 file changed

+5
-2
lines changed
  • apache-maven/src/assembly/maven/bin

1 file changed

+5
-2
lines changed

apache-maven/src/assembly/maven/bin/mvn.cmd

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ rem Compile the parser if not already compiled
185185
if not exist "%MAVEN_HOME%\bin\JvmConfigParser.class" (
186186
"%JAVACMD%" -d "%MAVEN_HOME%\bin" "%MAVEN_HOME%\bin\JvmConfigParser.java" >nul 2>&1
187187
)
188-
rem Run the parser
189-
for /f "delims=" %%i in ('"%JAVACMD%" -cp "%MAVEN_HOME%\bin" JvmConfigParser "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" "%MAVEN_PROJECTBASEDIR%" 2^>nul') do set JVM_CONFIG_MAVEN_OPTS=%%i
188+
rem Run the parser and save output to temp file to avoid pipe interpretation issues
189+
set "JVM_CONFIG_TEMP=%TEMP%\mvn-jvm-config-%RANDOM%.txt"
190+
"%JAVACMD%" -cp "%MAVEN_HOME%\bin" JvmConfigParser "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" "%MAVEN_PROJECTBASEDIR%" > "%JVM_CONFIG_TEMP%" 2>nul
191+
set /p JVM_CONFIG_MAVEN_OPTS=<"%JVM_CONFIG_TEMP%"
192+
del "%JVM_CONFIG_TEMP%" 2>nul
190193

191194
:endReadJvmConfig
192195

0 commit comments

Comments
 (0)