Skip to content

Commit d4ef9c0

Browse files
committed
Improve input validation
Signed-off-by: Wouter Born <github@maindrain.net>
1 parent d8dc22c commit d4ef9c0

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

alpine/Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ RUN apk update --no-cache && \
6565
zip && \
6666
# Install NodeJS only for openHAB >= 5
6767
if [ "$(echo $OPENHAB_VERSION | sed -E 's/^([0-9]+).*/\1/')" -ge 5 ]; then apk add --no-cache nodejs; fi && \
68-
# Configure default time zone
69-
ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && \
7068
# Fix issue with (arp)ping tool under non-root user for Docker+LXC setups
7169
# See: https://community.openhab.org/t/network-pingdevice-breaks-after-4-3-6-5-0-1-update-docker/166175
7270
chmod u+s /bin/ping && \

alpine/entrypoint

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@ set -eux -o pipefail ${EXTRA_SHELL_OPTS-}
55
IFS=$'\n\t'
66

77
# Configure time zone
8-
ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
8+
if [ -n "${TZ:-}" ]; then
9+
if grep -q " /etc/localtime " /proc/self/mountinfo; then
10+
echo "Warning: /etc/localtime is mounted. Please remove this volume mount and use the TZ environment variable instead."
11+
else
12+
if [ ! -f "/usr/share/zoneinfo/${TZ}" ]; then
13+
echo "Error: Invalid timezone '${TZ}' set in TZ environment variable" >&2
14+
exit 1
15+
fi
16+
ln -sf "/usr/share/zoneinfo/${TZ}" /etc/localtime
17+
fi
18+
else
19+
echo "TZ environment variable is not set. Skipping time zone configuration."
20+
fi
921

22+
# Determine Java home directory independent of JVM vendor, version and environment variables
1023
export JAVA_HOME=$(find /usr/lib/jvm -mindepth 1 -maxdepth 1 -type d)
1124

1225
# Configure Java unlimited strength cryptography

debian/entrypoint

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,21 @@ set -eux -o pipefail ${EXTRA_SHELL_OPTS-}
55
IFS=$'\n\t'
66

77
# Configure time zone
8-
ln -sf /usr/share/zoneinfo/$TZ /etc/localtime
8+
if [ -n "${TZ:-}" ]; then
9+
if mountpoint -q /etc/localtime; then
10+
echo "Warning: /etc/localtime is mounted. Please remove this volume mount and use the TZ environment variable instead."
11+
else
12+
if [ ! -f "/usr/share/zoneinfo/${TZ}" ]; then
13+
echo "Error: Invalid timezone '${TZ}' set in TZ environment variable" >&2
14+
exit 1
15+
fi
16+
ln -sf "/usr/share/zoneinfo/${TZ}" /etc/localtime
17+
fi
18+
else
19+
echo "TZ environment variable is not set. Skipping time zone configuration."
20+
fi
921

22+
# Determine Java home directory independent of JVM vendor, version and environment variables
1023
export JAVA_HOME=$(find /usr/lib/jvm -mindepth 1 -maxdepth 1 -type d)
1124

1225
# Configure Java unlimited strength cryptography

0 commit comments

Comments
 (0)