Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unescaped Path in JAVA_X Variable on Emulated Linux System (GIT Bash on Windows) #217

Open
Domenic-MZS opened this issue Nov 18, 2023 · 0 comments

Comments

@Domenic-MZS
Copy link

Unescaped Path in JAVA_X Variable on Emulated Linux System (GIT Bash on Windows)

Description:

Environment:

  • Operating System: Windows with emulated Linux system (e.g., GIT Bash on Windows)
  • Script: Bash script for initializing and running a FlureeDB instance

Issue:
When running the provided bash script in an emulated Linux environment on Windows (such as Bash on Windows), an error occurs related to the JAVA_X variable. The issue seems to stem from the way paths are handled in this mixed environment. Logs are attached below this:

$ ./fluree_start.sh
Java version 21.
Using logback config file ./logback.xml
No properties file specified. Using default properties file fluree_sample.properties.
Fluree ledger starting with properties file: ./fluree_sample.properties
Fluree ledger starting with java options: -Xms1g -Xmx2g -XX:+UseG1GC -XX:MaxGCPauseMillis=50
Log format is ansi
fluree.db log level is INFO
fluree.raft log level is INFO
./fluree_start.sh: line 226: /c/Program: No such file or directory

"This information was derived from a comment by user v_86 in the fluree Discord community on November 10, 2023, where they discussed about starting fluree on windows with git bash (fluree_start.sh)".

Probable Cause:
The script sets the JAVA_X variable, which holds the path to the Java executable. This is done in the find_java function:

JAVA_X=$(which java)
# or
JAVA_X="$JAVA_HOME/bin/java"

In a typical Linux environment, these paths are straightforward. However, when emulated on Windows, these paths may contain spaces or special characters typical to Windows file systems (like C:\Program Files\Java\jdk-11.0.1\bin\java). When such paths are used later in the script without proper escaping or quoting, they can lead to errors as it has been seen in the command log. This is particularly problematic in lines where JAVA_X is invoked:

exec $JAVA_X -Dfdb.command=$1 <more-args>...

Suggested Solution:
A potential solution is to ensure that JAVA_X is properly quoted whenever it is used. This can be done by modifying all instances where JAVA_X is used to "${JAVA_X}". This modification ensures that any spaces or special characters in the Java path are correctly handled by the shell on both platforms.


Steps to Reproduce:

  1. Set up a Windows system with an emulated Linux environment (e.g., GIT Bash with WSL or Cygwin).
  2. Ensure Java is installed in a typical Windows location with spaces in the path (e.g., C:\Program Files\Java\jdk-11.0.1).
  3. Run the provided bash script in the emulated environment.

Expected Result: The script initializes and runs the FlureeDB instance without issues.

Actual Result: An error occurs when the script tries to execute Java commands, likely due to an unescaped path in the JAVA_X variable.


Additional Information:

  • The script otherwise works as expected in a native Linux environment.
  • The issue highlights the importance of considering path differences in cross-platform scripts, especially in mixed environments like Bash on Windows.

Severity:

Medium - this affects usability in specific, but increasingly common, environments (Windows with Linux emulation).


Tags:

Bash, Windows, Linux Emulation, Path Escaping, Java, FlureeDB

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant