Skip to content

Commit 8954de6

Browse files
committed
Harden bash arrays creation against empty elements
1 parent 5d2c5bc commit 8954de6

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

dond

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ function set_docker_options_with_value() {
4040
local help_output
4141
help_output="$("${docker_path}" "${command[@]}" --help)"
4242

43-
local help_lines
44-
readarray -t help_lines <<<"${help_output}"
43+
local help_lines=()
44+
if [[ -n "${help_output}" ]]; then
45+
readarray -t help_lines <<<"${help_output}"
46+
fi
47+
unset help_output
48+
4549
docker_options_with_value=()
4650
for line in "${help_lines[@]}"; do
4751
# second group is the short option (optional)
@@ -110,14 +114,20 @@ function set_container_root_on_host() {
110114
# Reads the mounts of the current/parent container and stores them in the
111115
# parent_container_mounts array.
112116
function set_parent_container_mounts() {
113-
local docker_output
114-
docker_output=$(
117+
local inspect_output
118+
inspect_output=$(
115119
"${docker_path}" inspect \
116120
--format '{{range .Mounts}}{{if or (eq .Type "bind") (eq .Type "volume")}}{{printf "%s:%s\n" .Source .Destination}}{{end}}{{end}}' \
117121
"${container_id}"
118122
)
119123

120-
readarray -t parent_container_mounts <<<"${docker_output}"
124+
if [[ -n "${inspect_output}" ]]; then
125+
readarray -t parent_container_mounts <<<"${inspect_output}"
126+
else
127+
parent_container_mounts=()
128+
fi
129+
unset inspect_output
130+
121131
readonly parent_container_mounts
122132
}
123133

0 commit comments

Comments
 (0)