Skip to content

Commit 5e3ae9e

Browse files
committed
BUG: Fix splitting BWRAP_ARGS and _BWRAP_DEFAULT_ARGS
1 parent 6cc7efd commit 5e3ae9e

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

_wrapper_exe.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,19 @@ collect="$(
7979
echo "$path"; prev="$path"
8080
done)"
8181
82+
split_args_by_lf () {
83+
lf='
84+
'
85+
printf '%s' "$1" | case "$1" in *$lf*) cat ;; *) tr ' ' '\n' ;; esac; }
86+
8287
# Begins constructing args for bwrap, in reverse
8388
# (later args in command line override prior ones)
8489
IFS='
8590
' # Split args only on newline
86-
set -- $_BWRAP_DEFAULT_ARGS ${BWRAP_ARGS:-} "${0%/*}/$EXECUTABLE" "$@"
91+
# shellcheck disable=SC2046
92+
set -- $(split_args_by_lf "$_BWRAP_DEFAULT_ARGS") \
93+
$(split_args_by_lf "${BWRAP_ARGS:-}") \
94+
"${0%/*}/$EXECUTABLE" "$@"
8795
8896
for path in $collect; do set -- --ro-bind "$path" "$path" "$@"; done
8997

_wrapper_pip.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ venv="$(realpath "${0%/*}/..")"
88

99
_BWRAP_DEFAULT_ARGS=
1010

11-
BWRAP_ARGS="$_BWRAP_DEFAULT_ARGS
12-
${BWRAP_ARGS-}
11+
# AUX_FUNCS: Auxiliary functions get inserted here
12+
13+
BWRAP_ARGS="$(split_args_by_lf "$_BWRAP_DEFAULT_ARGS")
1314
--bind
1415
$venv
15-
$venv" \
16+
$venv
17+
$(split_args_by_lf "${BWRAP_ARGS-}")" \
1618
"$venv/bin/.unsafe_${0##*/}" "$@"
1719
pip_return_status=$?
1820

19-
# AUX_FUNCS: Auxiliary functions get inserted here
20-
2121
new_binaries="$(
2222
for file in "$venv/bin"/*; do
2323
[ -L "$file" ] || [ ! -x "$file" ] ||

build/sandbox-venv

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ extract_segment () {
3838
wrap_pip () {
3939
out="$1"; shift
4040
extract_segment 1 "$@" > "$out"
41-
printf '%s\n%s\n' "$(export_func is_python_shebang)" "$(export_func is_already_wrapped)" |
41+
printf '%s\n%s\n%s\n' \
42+
"$(export_func split_args_by_lf)" \
43+
"$(export_func is_python_shebang)" \
44+
"$(export_func is_already_wrapped)" |
4245
sed -i -E '/^# AUX_FUNCS.*/{
4346
r /dev/stdin
4447
d}' "$out"
@@ -82,23 +85,22 @@ exit 0
8285
# sandbox-venv: Secure container sandbox venv wrapper (GENERATED CODE)
8386
# pip wrapper: Re-run sandbox-venv after every pip installation
8487
set -u
85-
set -x
8688
alias realpath='realpath --no-symlinks'
8789

8890
venv="$(realpath "${0%/*}/..")"
8991

9092
_BWRAP_DEFAULT_ARGS=
9193

92-
BWRAP_ARGS="$_BWRAP_DEFAULT_ARGS
93-
${BWRAP_ARGS-}
94+
# AUX_FUNCS: Auxiliary functions get inserted here
95+
96+
BWRAP_ARGS="$(split_args_by_lf "$_BWRAP_DEFAULT_ARGS")
9497
--bind
9598
$venv
96-
$venv" \
99+
$venv
100+
$(split_args_by_lf "${BWRAP_ARGS-}")" \
97101
"$venv/bin/.unsafe_${0##*/}" "$@"
98102
pip_return_status=$?
99103

100-
# AUX_FUNCS: Auxiliary functions get inserted here
101-
102104
new_binaries="$(
103105
for file in "$venv/bin"/*; do
104106
[ -L "$file" ] || [ ! -x "$file" ] ||
@@ -203,11 +205,19 @@ collect="$(
203205
echo "$path"; prev="$path"
204206
done)"
205207
208+
split_args_by_lf () {
209+
lf='
210+
'
211+
printf '%s' "$1" | case "$1" in *$lf*) cat ;; *) tr ' ' '\n' ;; esac; }
212+
206213
# Begins constructing args for bwrap, in reverse
207214
# (later args in command line override prior ones)
208215
IFS='
209216
' # Split args only on newline
210-
set -- $_BWRAP_DEFAULT_ARGS ${BWRAP_ARGS:-} "${0%/*}/$EXECUTABLE" "$@"
217+
# shellcheck disable=SC2046
218+
set -- $(split_args_by_lf "$_BWRAP_DEFAULT_ARGS") \
219+
$(split_args_by_lf "${BWRAP_ARGS:-}") \
220+
"${0%/*}/$EXECUTABLE" "$@"
211221
212222
for path in $collect; do set -- --ro-bind "$path" "$path" "$@"; done
213223

sandbox-venv.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ extract_segment () {
3838
wrap_pip () {
3939
out="$1"; shift
4040
extract_segment 1 "$@" > "$out"
41-
printf '%s\n%s\n' "$(export_func is_python_shebang)" "$(export_func is_already_wrapped)" |
41+
printf '%s\n%s\n%s\n' \
42+
"$(export_func split_args_by_lf)" \
43+
"$(export_func is_python_shebang)" \
44+
"$(export_func is_already_wrapped)" |
4245
sed -i -E '/^# AUX_FUNCS.*/{
4346
r /dev/stdin
4447
d}' "$out"

0 commit comments

Comments
 (0)