fix: avoid operand evaluation as argument

Explicit end option parsing as the shell can be quite dangerous without
it.
This commit is contained in:
Ben Grande 2024-08-06 17:04:16 +02:00
parent e42950376a
commit 1b2f1ba941
No known key found for this signature in database
GPG key ID: 00C64E14F51F9E56
52 changed files with 196 additions and 189 deletions

View file

@ -23,14 +23,14 @@ Example:
ls_agent(){
socket="/tmp/${service}/${agent}.sock"
test -S "${socket}" || return 1
agent="$(echo "${socket}" | sed "s|.*${service}/||;s/\.sock//")"
agent="$(echo "${socket}" | sed -e "s|.*${service}/||;s/\.sock//")"
echo "Agent: (${agent}) ${socket}"
SSH_AUTH_SOCK="${socket}" ssh-add -l || true
}
add_agent(){
# shellcheck disable=SC2174
mkdir -m 0700 -p "/tmp/${service}"
mkdir -m 0700 -p -- "/tmp/${service}"
dir="${HOME}/.ssh/identities.d/${agent}"
if ! test -d "${dir}"; then
echo "Directory not found: ${dir}" >&2
@ -45,8 +45,8 @@ add_agent(){
if ! test "${reload_agent}" = "1"; then
return
fi
keys="$(grep -sl -- "-----BEGIN OPENSSH PRIVATE KEY-----" \
"${HOME}/.ssh/identities.d/${dir}"/* || true)"
keys="$(grep -sl -e "-----BEGIN OPENSSH PRIVATE KEY-----" \
-- "${HOME}/.ssh/identities.d/${dir}"/* || true)"
if test -z "${keys}"; then
echo "Directory has no key: ${dir}" >&2
return 1
@ -56,7 +56,7 @@ add_agent(){
test -f "${k}" || continue
ssh_add_option=""
if test -f "${k}.ssh-add-option"; then
ssh_add_option="$(cat "${k}.ssh-add-option")"
ssh_add_option="$(cat -- "${k}.ssh-add-option")"
fi
# shellcheck disable=SC2086
SSH_AUTH_SOCK="${socket}" ssh-add ${ssh_add_option} "${k}"