fluree / ledger

Fluree ledger server source
GNU Affero General Public License v3.0
77 stars 8 forks source link

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

Open Domenic-MZS opened 11 months ago

Domenic-MZS commented 11 months ago

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

Description:

Environment:

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:


Severity:

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


Tags:

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