ci/lib: do not interpret escape sequences in `group ()` arguments
We use printf to set up sections with GitLab CI, which requires us to print a bunch of escape sequences via printf. The group name is controlled by the user and is expanded directly into the formatting string, which may cause problems in case the argument contains escape sequences or formatting directives. Fix this potential issue by using formatting directives to pass variable data. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Dec 12, 2024 at 07:47 UTC
d2ca12020ffb7ee7f0ee1154f394a994f045b5a9
1 file changed
+4
-2
ci/lib.sh
+4
-2
@@ -18,7 +18,8 @@ elif test true = "$GITLAB_CI"
18
then
19
begin_group () {
20
need_to_end_group=t
21
- printf "\e[0Ksection_start:$(date +%s):$(echo "$1" | tr ' ' _)[collapsed=true]\r\e[0K$1\n"
21
+ printf '\e[0Ksection_start:%s:%s[collapsed=true]\r\e[0K%s\n' \
22
+ "$(date +%s)" "$(echo "$1" | tr ' ' _)" "$1"
23
trap "end_group '$1'" EXIT
24
set -x
25
}
@@ -27,7 +28,8 @@ then
28
test -n "$need_to_end_group" || return 0
29
set +x
30
need_to_end_group=
30
- printf "\e[0Ksection_end:$(date +%s):$(echo "$1" | tr ' ' _)\r\e[0K\n"
31
+ printf '\e[0Ksection_end:%s:%s\r\e[0K\n' \
32
+ "$(date +%s)" "$(echo "$1" | tr ' ' _)"
33
trap - EXIT
34
}
35
else