Skip to content

Commit

Permalink
Bugfix: Allow opensearch.bat file and opensearch-env.bat files to run…
Browse files Browse the repository at this point in the history
… when install path includes a space. (#4362)

* Bugfix: Prevent escaping of in `else-if` statement by setting variable without double quotes.

Signed-off-by: Mike Wilkinson <[email protected]>

* Add changelog entry for fix

Signed-off-by: Mike Wilkinson <[email protected]>

* Escape double quotes for environment variables set by `opensearch-env.bat`. Explicitly apply quotes where those environment variables are invoked.

Signed-off-by: Mike Wilkinson <[email protected]>

Signed-off-by: Mike Wilkinson <[email protected]>
Co-authored-by: Mike Wilkinson <[email protected]>
  • Loading branch information
2 people authored and peterzhuamazon committed Sep 9, 2022
1 parent 6f6e84e commit 0ec1c22
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed cancellation of segment replication events ([#4225](https://github.com/opensearch-project/OpenSearch/pull/4225))
- Bugs for dependabot changelog verifier workflow ([#4364](https://github.com/opensearch-project/OpenSearch/pull/4364))
- [Bug]: gradle check failing with java heap OutOfMemoryError (([#4328](https://github.com/opensearch-project/OpenSearch/
- `opensearch.bat` fails to execute when install path includes spaces ([#4362](https://github.com/opensearch-project/OpenSearch/pull/4362))

### Security
- CVE-2022-25857 org.yaml:snakeyaml DOS vulnerability ([#4341](https://github.com/opensearch-project/OpenSearch/pull/4341))
Expand Down
2 changes: 1 addition & 1 deletion distribution/src/bin/opensearch-cli.bat
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rem use a small heap size for the CLI tools, and thus the serial collector to
rem avoid stealing many CPU cycles; a user can override by setting OPENSEARCH_JAVA_OPTS
set OPENSEARCH_JAVA_OPTS=-Xms4m -Xmx64m -XX:+UseSerialGC %OPENSEARCH_JAVA_OPTS%

%JAVA% ^
"%JAVA%" ^
%OPENSEARCH_JAVA_OPTS% ^
-Dopensearch.path.home="%OPENSEARCH_HOME%" ^
-Dopensearch.path.conf="%OPENSEARCH_PATH_CONF%" ^
Expand Down
10 changes: 5 additions & 5 deletions distribution/src/bin/opensearch-env.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ rem comparing to empty string makes this equivalent to bash -v check on env var
rem and allows to effectively force use of the bundled jdk when launching OpenSearch
rem by setting OPENSEARCH_JAVA_HOME= and JAVA_HOME=
if not "%OPENSEARCH_JAVA_HOME%" == "" (
set JAVA="%OPENSEARCH_JAVA_HOME%\bin\java.exe"
set "JAVA=%OPENSEARCH_JAVA_HOME%\bin\java.exe"
set JAVA_TYPE=OPENSEARCH_JAVA_HOME
) else if not "%JAVA_HOME%" == "" (
set JAVA="%JAVA_HOME%\bin\java.exe"
set "JAVA=%JAVA_HOME%\bin\java.exe"
set JAVA_TYPE=JAVA_HOME
) else (
set JAVA="%OPENSEARCH_HOME%\jdk\bin\java.exe"
set JAVA_HOME="%OPENSEARCH_HOME%\jdk"
set "JAVA=%OPENSEARCH_HOME%\jdk\bin\java.exe"
set "JAVA_HOME=%OPENSEARCH_HOME%\jdk"
set JAVA_TYPE=bundled jdk
)

Expand All @@ -73,4 +73,4 @@ if defined JAVA_OPTS (
)

rem check the Java version
%JAVA% -cp "%OPENSEARCH_CLASSPATH%" "org.opensearch.tools.java_version_checker.JavaVersionChecker" || exit /b 1
"%JAVA%" -cp "%OPENSEARCH_CLASSPATH%" "org.opensearch.tools.java_version_checker.JavaVersionChecker" || exit /b 1
4 changes: 2 additions & 2 deletions distribution/src/bin/opensearch-service.bat
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ if exist "%JAVA_HOME%\bin\server\jvm.dll" (

:foundJVM
if not defined OPENSEARCH_TMPDIR (
for /f "tokens=* usebackq" %%a in (`CALL %JAVA% -cp "!OPENSEARCH_CLASSPATH!" "org.opensearch.tools.launchers.TempDirectory"`) do set OPENSEARCH_TMPDIR=%%a
for /f "tokens=* usebackq" %%a in (`CALL "%JAVA%" -cp "!OPENSEARCH_CLASSPATH!" "org.opensearch.tools.launchers.TempDirectory"`) do set OPENSEARCH_TMPDIR=%%a
)

rem The JVM options parser produces the final JVM options to start
Expand All @@ -135,7 +135,7 @@ rem - third, JVM options from OPENSEARCH_JAVA_OPTS are applied
rem - fourth, ergonomic JVM options are applied

@setlocal
for /F "usebackq delims=" %%a in (`CALL %JAVA% -cp "!OPENSEARCH_CLASSPATH!" "org.opensearch.tools.launchers.JvmOptionsParser" "!OPENSEARCH_PATH_CONF!" ^|^| echo jvm_options_parser_failed`) do set OPENSEARCH_JAVA_OPTS=%%a
for /F "usebackq delims=" %%a in (`CALL "%JAVA%" -cp "!OPENSEARCH_CLASSPATH!" "org.opensearch.tools.launchers.JvmOptionsParser" "!OPENSEARCH_PATH_CONF!" ^|^| echo jvm_options_parser_failed`) do set OPENSEARCH_JAVA_OPTS=%%a
@endlocal & set "MAYBE_JVM_OPTIONS_PARSER_FAILED=%OPENSEARCH_JAVA_OPTS%" & set OPENSEARCH_JAVA_OPTS=%OPENSEARCH_JAVA_OPTS%

if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (
Expand Down
6 changes: 3 additions & 3 deletions distribution/src/bin/opensearch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ IF "%checkpassword%"=="Y" (
)

if not defined OPENSEARCH_TMPDIR (
for /f "tokens=* usebackq" %%a in (`CALL %JAVA% -cp "!OPENSEARCH_CLASSPATH!" "org.opensearch.tools.launchers.TempDirectory"`) do set OPENSEARCH_TMPDIR=%%a
for /f "tokens=* usebackq" %%a in (`CALL "%JAVA%" -cp "!OPENSEARCH_CLASSPATH!" "org.opensearch.tools.launchers.TempDirectory"`) do set OPENSEARCH_TMPDIR=%%a
)

rem The JVM options parser produces the final JVM options to start
Expand All @@ -88,7 +88,7 @@ rem jvm.options.d/*.options
rem - third, JVM options from OPENSEARCH_JAVA_OPTS are applied
rem - fourth, ergonomic JVM options are applied
@setlocal
for /F "usebackq delims=" %%a in (`CALL %JAVA% -cp "!OPENSEARCH_CLASSPATH!" "org.opensearch.tools.launchers.JvmOptionsParser" "!OPENSEARCH_PATH_CONF!" ^|^| echo jvm_options_parser_failed`) do set OPENSEARCH_JAVA_OPTS=%%a
for /F "usebackq delims=" %%a in (`CALL "%JAVA%" -cp "!OPENSEARCH_CLASSPATH!" "org.opensearch.tools.launchers.JvmOptionsParser" "!OPENSEARCH_PATH_CONF!" ^|^| echo jvm_options_parser_failed`) do set OPENSEARCH_JAVA_OPTS=%%a
@endlocal & set "MAYBE_JVM_OPTIONS_PARSER_FAILED=%OPENSEARCH_JAVA_OPTS%" & set OPENSEARCH_JAVA_OPTS=%OPENSEARCH_JAVA_OPTS%

if "%MAYBE_JVM_OPTIONS_PARSER_FAILED%" == "jvm_options_parser_failed" (
Expand All @@ -103,7 +103,7 @@ SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^<=^^^<!
SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^>=^^^>!
SET KEYSTORE_PASSWORD=!KEYSTORE_PASSWORD:^\=^^^\!

ECHO.!KEYSTORE_PASSWORD!| %JAVA% %OPENSEARCH_JAVA_OPTS% -Dopensearch ^
ECHO.!KEYSTORE_PASSWORD!| "%JAVA%" %OPENSEARCH_JAVA_OPTS% -Dopensearch ^
-Dopensearch.path.home="%OPENSEARCH_HOME%" -Dopensearch.path.conf="%OPENSEARCH_PATH_CONF%" ^
-Dopensearch.distribution.type="%OPENSEARCH_DISTRIBUTION_TYPE%" ^
-Dopensearch.bundled_jdk="%OPENSEARCH_BUNDLED_JDK%" ^
Expand Down

0 comments on commit 0ec1c22

Please sign in to comment.