Skip to content
This repository was archived by the owner on Aug 29, 2018. It is now read-only.

Commit 7a0be75

Browse files
author
Vu Dinh
committed
Tomcat does not properly parse spaces in JVM parameters
Tomcat script doesn't correct handle the white places in the parameters passing via env variable JAVA_OPTS_EXT which causes the JVM fails to parse the parameters correctly during execution. The tomcat bash script is modified to handle the white spaces and ensured the space is not ignored by adding the extra double quotes around the "JAVA_OPTS_EXT". Bug: 1282852 Link: <https://bugzilla.redhat.com/show_bug.cgi?id=1282852> Signed-off-by: Vu Dinh <vdinh@redhat.com>
1 parent 96ab0c0 commit 7a0be75

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

  • cartridges/openshift-origin-cartridge-jbossews/bin

cartridges/openshift-origin-cartridge-jbossews/bin/tomcat

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,14 @@ memory_options="-Xms40m -Xmx${max_heap}m -XX:MaxPermSize=${max_permgen}m -XX:+Ag
3232
# Specify options to pass to the Java VM.
3333
#
3434
if [ -z "$JAVA_OPTS" ]; then
35-
JAVA_OPTS="$memory_options -DOPENSHIFT_APP_UUID=${OPENSHIFT_APP_UUID} -Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true"
35+
JAVA_OPTS="$memory_options -DOPENSHIFT_APP_UUID=${OPENSHIFT_APP_UUID} -Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.net.preferIPv4Stack=true -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true"
3636

3737
if marker_present "enable_jpda"; then
3838
echo "enable_jpda marker found; enabling debugging on ${OPENSHIFT_JBOSSEWS_IP}:${OPENSHIFT_JBOSSEWS_JPDA_PORT}"
3939
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=${OPENSHIFT_JBOSSEWS_IP}:${OPENSHIFT_JBOSSEWS_JPDA_PORT},server=y,suspend=n"
4040
fi
4141
fi
4242

43-
if [ -n "$JAVA_OPTS_EXT" ]; then
44-
JAVA_OPTS="$JAVA_OPTS $JAVA_OPTS_EXT"
45-
fi
46-
4743
JAVACMD=$JAVA_HOME/bin/java
4844

4945
# CLASSPATH munging
@@ -86,9 +82,28 @@ EOF
8682
fi
8783
done
8884

85+
# Split the input nicely into multiple arguments for JVM
86+
# Although we attempt to sanitize $input, using eval on user input is always risky.
87+
# Doing so is acceptable here because we are in the gear user's SELinux context,
88+
# but we must be mindful not to re-use this function outside the gear user's context.
89+
sh_split() {
90+
local input="$*"
91+
input="${input//\\/\\\\}"
92+
input="${input//\`/\\\`}"
93+
input="${input//\$/\\$}"
94+
input="${input//$'\n'/ }"
95+
input="${input//;/\\;}"
96+
eval "set -- $input"
97+
args=( "$@" )
98+
}
99+
100+
if [ -n "$JAVA_OPTS_EXT" ]; then
101+
sh_split "$JAVA_OPTS_EXT"
102+
fi
103+
89104
# Control the Tomcat instance
90105
if [ "$1" = "start" ]; then
91-
${JAVACMD} $JAVA_OPTS $LOGGING_CONFIG $CATALINA_OPTS \
106+
${JAVACMD} $JAVA_OPTS ${JAVA_OPTS_EXT:+"${args[@]}"} $LOGGING_CONFIG $CATALINA_OPTS \
92107
-classpath "$CLASSPATH" \
93108
-Dcatalina.base="$CATALINA_BASE" \
94109
-Dcatalina.home="$CATALINA_HOME" \
@@ -99,20 +114,20 @@ if [ "$1" = "start" ]; then
99114
echo $! > $CATALINA_PID
100115
fi
101116
elif [ "$1" = "start-security" ]; then
102-
${JAVACMD} $JAVA_OPTS $LOGGING_CONFIG $CATALINA_OPTS \
117+
${JAVACMD} $JAVA_OPTS ${JAVA_OPTS_EXT:+"${args[@]}"} $LOGGING_CONFIG $CATALINA_OPTS \
103118
-classpath "$CLASSPATH" \
104119
-Dcatalina.base="$CATALINA_BASE" \
105120
-Dcatalina.home="$CATALINA_HOME" \
106121
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
107122
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
108123
-Djava.security.manager \
109124
-Djava.security.policy=="${CATALINA_BASE}/conf/catalina.policy" \
110-
org.apache.catalina.startup.Bootstrap start 2>&1
125+
org.apache.catalina.startup.Bootstrap start 2>&1
111126
if [ ! -z "$CATALINA_PID" ]; then
112127
echo $! > $CATALINA_PID
113128
fi
114129
elif [ "$1" = "stop" ]; then
115-
${JAVACMD} $JAVA_OPTS $LOGGING_CONFIG \
130+
${JAVACMD} $JAVA_OPTS ${JAVA_OPTS_EXT:+"${args[@]}"} $LOGGING_CONFIG \
116131
-classpath "$CLASSPATH" \
117132
-Dcatalina.base="$CATALINA_BASE" \
118133
-Dcatalina.home="$CATALINA_HOME" \

0 commit comments

Comments
 (0)