Skip to content

Commit c727e98

Browse files
authored
chore: Wrapper script variables protection (#280)
1 parent 5c03346 commit c727e98

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

build/trivalent.sh

+17-29
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,33 @@
11
#!/bin/bash
22

3-
# Sanitize risky env variables
4-
export PATH="/usr/bin:/bin"
5-
export LD_PRELOAD=""
6-
export LD_LIBRARY_PATH=""
7-
export LD_AUDIT=""
8-
export LD_PROFILE=""
3+
# Sanitize & protect risky variables
4+
readonly HOME="$HOME"
5+
readonly PATH="/usr/bin:/bin"
6+
readonly LD_PRELOAD=""
7+
readonly LD_LIBRARY_PATH=""
8+
readonly LD_AUDIT=""
9+
readonly LD_PROFILE=""
910

1011
# unify branding
11-
export CHROMIUM_NAME="@@CHROMIUM_NAME@@"
12+
readonly CHROMIUM_NAME="@@CHROMIUM_NAME@@"
1213

1314
# Let the wrapped binary know that it has been run through the wrapper.
14-
export CHROME_WRAPPER="`readlink -f "$0"`"
15+
readonly CHROME_WRAPPER="`readlink -f "$0"`"
16+
readonly HERE="`dirname "$CHROME_WRAPPER"`"
1517

16-
HERE="`dirname "$CHROME_WRAPPER"`"
17-
18-
# We include some xdg utilities next to the binary, and we want to prefer them
19-
# over the system versions when we know the system versions are very old. We
20-
# detect whether the system xdg utilities are sufficiently new to be likely to
21-
# work for us by looking for xdg-settings. If we find it, we leave $PATH alone,
22-
# so that the system xdg utilities (including any distro patches) will be used.
23-
if ! which xdg-settings &> /dev/null; then
24-
# Old xdg utilities. Prepend $HERE to $PATH to use ours instead.
25-
export PATH="$HERE:$PATH"
26-
else
27-
# Use system xdg utilities. But first create mimeapps.list if it doesn't
28-
# exist; some systems have bugs in xdg-mime that make it fail without it.
29-
xdg_app_dir="${XDG_DATA_HOME:-$HOME/.local/share/applications}"
30-
mkdir -p "$xdg_app_dir"
31-
[ -f "$xdg_app_dir/mimeapps.list" ] || touch "$xdg_app_dir/mimeapps.list"
32-
fi
18+
# obtain chromium flags from system file
19+
[[ -f /etc/$CHROMIUM_NAME/$CHROMIUM_NAME.conf ]] && . /etc/$CHROMIUM_NAME/$CHROMIUM_NAME.conf
20+
readonly CHROMIUM_FLAGS="$CHROMIUM_FLAGS"
3321

3422
export CHROME_VERSION_EXTRA="Built from source for @@BUILD_TARGET@@"
3523

3624
# We don't want bug-buddy intercepting our crashes. http://crbug.com/24120
3725
export GNOME_DISABLE_CRASH_DIALOG=SET_BY_GOOGLE_CHROME
3826

39-
# Allow users to override command-line options and prefer user defined
40-
# CHROMIUM_USER_FLAGS from env over system wide CHROMIUM_FLAGS
41-
[[ -f /etc/$CHROMIUM_NAME/$CHROMIUM_NAME.conf ]] && . /etc/$CHROMIUM_NAME/$CHROMIUM_NAME.conf
42-
CHROMIUM_FLAGS=${CHROMIUM_USER_FLAGS:-$CHROMIUM_FLAGS}
27+
# desktop integration
28+
xdg_app_dir="${XDG_DATA_HOME:-$HOME/.local/share/applications}"
29+
mkdir -p "$xdg_app_dir"
30+
[ -f "$xdg_app_dir/mimeapps.list" ] || touch "$xdg_app_dir/mimeapps.list"
4331

4432
# handle migration from the old directory
4533
# the migration file just tells this wrapper not to copy over data

0 commit comments

Comments
 (0)