@@ -58,36 +58,10 @@ function parse_java_property() {
5858
5959# Properly split java options, dealing with whitespace, double quotes and backslashes.
6060# This accepts a string and returns the resulting list through SPLIT_JAVA_OPTS.
61+ # For security reasons, this is isolated in its own function.
6162function split_java_options() {
62- SPLIT_JAVA_OPTS=() # return value
63- option_buffer=" " # buffer for collecting parts of an option
64- opened_quotes=0 # whether we are expecting a closing double quotes
65- for word in $1 ; do
66- num_quotes=$( echo " $word " | sed " s/\\\\\" //g" | grep -o " \" " | grep -c .)
67- if [[ $(( num_quotes % 2 )) == 1 ]]; then
68- # Flip the bit
69- opened_quotes=$(( (opened_quotes + 1 ) % 2 ))
70- fi
71- if [[ $opened_quotes == 0 ]]; then
72- # Remove all non-escaped quotes around the value
73- SPLIT_JAVA_OPTS+=(" $(
74- echo " $option_buffer $word " | \
75- sed " s/^[[:space:]]*//" | \
76- sed " s/\([^\\ ]\)\" /\1/g" | \
77- sed " s/\\\\ \([\\\" ]\)/\1/g"
78- ) " )
79- option_buffer=" "
80- else
81- # We are expecting a closing double quote, so keep buffering
82- option_buffer=" $option_buffer $word "
83- fi
84- done
85- # Something is wrong if we ended with open double quotes
86- if [[ $opened_quotes == 1 ]]; then
87- echo -e " Java options parse error! Expecting closing double quotes:" 1>&2
88- echo -e " ${SPLIT_JAVA_OPTS[@]} " 1>&2
89- exit 1
90- fi
63+ eval set -- " $1 "
64+ SPLIT_JAVA_OPTS=(" $@ " )
9165 export SPLIT_JAVA_OPTS
9266}
9367
0 commit comments