Skip to content

Commit fb91f87

Browse files
PatDynMathieu Fenniak
authored andcommitted
fix: bad quoting in hook scripts allow word splitting, leading to hook script errors (#13679)
Fixes #13662 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/13679 Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
1 parent 0cecdcd commit fb91f87

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

modules/git/hook_generate.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ func getHookTemplates() (hookNames, hookTpls, giteaHookTpls []string) {
2020
# AUTO GENERATED BY GITEA, DO NOT MODIFY
2121
data=$(cat)
2222
exitcodes=""
23-
hookname=$(basename $0)
23+
hookname=$(basename "$0")
2424
25-
for hook in $(dirname $0)/${hookname}.d/*; do
25+
for hook in "$(dirname "$0")/${hookname}.d"/*; do
2626
test -x "${hook}" && test -f "${hook}" || continue
2727
echo "${data}" | "${hook}"
2828
exitcodes="${exitcodes} $?"
@@ -31,8 +31,8 @@ done
3131
# Custom hooks
3232
custom_hooks_dir="./hooks/${hookname}.d"
3333
if [ -d "${custom_hooks_dir}" ]; then
34-
for hook in ${custom_hooks_dir}/*; do
35-
if [ $(basename "${hook}") != "gitea" ]; then
34+
for hook in "${custom_hooks_dir}"/*; do
35+
if [ "$(basename "${hook}")" != "gitea" ]; then
3636
test -x "${hook}" && test -f "${hook}" || continue
3737
echo "${data}" | "${hook}"
3838
exitcodes="${exitcodes} $?"
@@ -41,36 +41,36 @@ if [ -d "${custom_hooks_dir}" ]; then
4141
fi
4242
4343
for i in ${exitcodes}; do
44-
[ ${i} -eq 0 ] || exit ${i}
44+
[ "${i}" -eq 0 ] || exit "${i}"
4545
done
4646
`, setting.ScriptType),
4747

4848
// for update
4949
fmt.Sprintf(`#!/usr/bin/env %s
5050
# AUTO GENERATED BY GITEA, DO NOT MODIFY
5151
exitcodes=""
52-
hookname=$(basename $0)
52+
hookname=$(basename "$0")
5353
54-
for hook in $(dirname $0)/${hookname}.d/*; do
54+
for hook in "$(dirname "$0")/${hookname}.d"/*; do
5555
test -x "${hook}" && test -f "${hook}" || continue
56-
"${hook}" $1 $2 $3
56+
"${hook}" "$1" "$2" "$3"
5757
exitcodes="${exitcodes} $?"
5858
done
5959
6060
# Custom hooks
6161
custom_hooks_dir="./hooks/${hookname}.d"
6262
if [ -d "${custom_hooks_dir}" ]; then
63-
for hook in ${custom_hooks_dir}/*; do
64-
if [ $(basename "${hook}") != "gitea" ]; then
63+
for hook in "${custom_hooks_dir}"/*; do
64+
if [ "$(basename "${hook}")" != "gitea" ]; then
6565
test -x "${hook}" && test -f "${hook}" || continue
66-
"${hook}" $1 $2 $3
66+
"${hook}" "$1" "$2" "$3"
6767
exitcodes="${exitcodes} $?"
6868
fi
6969
done
7070
fi
7171
7272
for i in ${exitcodes}; do
73-
[ ${i} -eq 0 ] || exit ${i}
73+
[ "${i}" -eq 0 ] || exit "${i}"
7474
done
7575
`, setting.ScriptType),
7676

@@ -79,9 +79,9 @@ done
7979
# AUTO GENERATED BY GITEA, DO NOT MODIFY
8080
data=$(cat)
8181
exitcodes=""
82-
hookname=$(basename $0)
82+
hookname=$(basename "$0")
8383
84-
for hook in $(dirname $0)/${hookname}.d/*; do
84+
for hook in "$(dirname "$0")/${hookname}.d"/*; do
8585
test -x "${hook}" && test -f "${hook}" || continue
8686
echo "${data}" | "${hook}"
8787
exitcodes="${exitcodes} $?"
@@ -90,16 +90,16 @@ done
9090
# Custom hooks
9191
custom_hooks_dir="./hooks/${hookname}.d"
9292
if [ -d "${custom_hooks_dir}" ]; then
93-
for hook in ${custom_hooks_dir}/*; do
94-
if [ $(basename "${hook}") != "gitea" ]; then
93+
for hook in "${custom_hooks_dir}"/*; do
94+
if [ "$(basename "${hook}")" != "gitea" ]; then
9595
test -x "${hook}" && test -f "${hook}" || continue
9696
echo "${data}" | "${hook}"
9797
exitcodes="${exitcodes} $?"
9898
fi
9999
done
100100
fi
101101
for i in ${exitcodes}; do
102-
[ ${i} -eq 0 ] || exit ${i}
102+
[ "${i}" -eq 0 ] || exit "${i}"
103103
done
104104
`, setting.ScriptType),
105105
}

0 commit comments

Comments
 (0)