abuild: fix check of maintainer address

Also disallow leading and trailing spaces/quotes.

fixes https://gitlab.alpinelinux.org/alpine/abuild/-/issues/10080
This commit is contained in:
Natanael Copa 2022-12-02 16:17:39 +01:00
parent 37e150738e
commit ee13f777d5
2 changed files with 27 additions and 5 deletions

View File

@ -969,8 +969,6 @@ git_last_commit_epoch() {
get_maintainer() {
if [ -z "$maintainer" ]; then
maintainer=$(awk -F': ' '/# *Maintainer/ {print $2}' "$APKBUILD")
# remove surrounding whitespace
maintainer=$(echo "$maintainer" | xargs)
fi
}
@ -981,8 +979,10 @@ check_maintainer() {
else
# try to check for a valid rfc822 address
case "$maintainer" in
*[A-Za-z0-9]*\ \<*@*.*\>) ;;
*) return 1 ;;
" "*|*" ") error "'$maintainer' has leading or trailing space"; return 1 ;;
\"*|*\") error "'$maintainer' has leading or trailing quote"; return 1 ;;
*\ \<*@*.*\>) ;;
*) error "'$maintainer' is not a valid rfc822 address"; return 1 ;;
esac
fi
}

View File

@ -27,7 +27,8 @@ init_tests \
abuild_package_size_nonzero \
abuild_amove \
abuild_doc \
abuild_dev
abuild_dev \
abuild_check_maintainer
export ABUILD_SHAREDIR=$(atf_get_srcdir)/..
export ABUILD_CONF=/dev/null
@ -673,3 +674,24 @@ abuild_dev_body() {
done
test -L pkg/foo-dev/usr/lib/libfoo.so || atf_fail "libfoo.so failed"
}
abuild_check_maintainer_body() {
mkdir -p foo && cd foo
for m in "Test User 123 <123example.com>" \
"foo" \
"user@example.com" \
" Leading Space <n@example.com>" \
"Trailing Space <n@example.com> " \
"Foo<u@example.com>" \
'"Quotes <u@example.com>"'; do
printf "# Maintainer: %s\n%s\n" "$m" "pkgname=foo" > APKBUILD
atf_check -s not-exit:0 \
-e match:"ERROR:" \
abuild check_maintainer
done
for m in "Test User <123@example.com>" "Foo O'Brian <n@example.com>" "Łukasz Something <s@example.com>"; do
printf "# Maintainer: %s\n%s\n" "$m" "pkgname=foo" > APKBUILD
atf_check abuild check_maintainer
done
}