makepkg: reject package data with newlines

The PKGINFO format cannot handle values that contain newlines.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Andrew Gregory 2016-11-05 18:08:15 -04:00 committed by Allan McRae
parent d3dc200263
commit 46101bea1c

View file

@ -600,6 +600,19 @@ find_libprovides() {
(( ${#libprovides[@]} )) && printf '%s\n' "${libprovides[@]}" (( ${#libprovides[@]} )) && printf '%s\n' "${libprovides[@]}"
} }
write_kv_pair() {
local key="$1"
shift
for val in "$@"; do
if [[ $val = *$'\n'* ]]; then
error "$(gettext "Invalid value for %s: %s")" "$key" "$val"
exit 1
fi
printf "%s = %s\n" "$key" "$val"
done
}
write_pkginfo() { write_pkginfo() {
local builddate=$(date -u "+%s") local builddate=$(date -u "+%s")
if [[ -n $PACKAGER ]]; then if [[ -n $PACKAGER ]]; then
@ -618,15 +631,15 @@ write_pkginfo() {
printf "# using %s\n" "$(fakeroot -v)" printf "# using %s\n" "$(fakeroot -v)"
printf "# %s\n" "$(LC_ALL=C date -u)" printf "# %s\n" "$(LC_ALL=C date -u)"
printf "pkgname = %s\n" "$pkgname" write_kv_pair "pkgname" "$pkgname"
if (( SPLITPKG )) || [[ "$pkgbase" != "$pkgname" ]]; then if (( SPLITPKG )) || [[ "$pkgbase" != "$pkgname" ]]; then
printf "pkgbase = %s\n" "$pkgbase" write_kv_pair "pkgbase" "$pkgbase"
fi fi
local fullver=$(get_full_version) local fullver=$(get_full_version)
printf "pkgver = %s\n" "$fullver" write_kv_pair "pkgver" "$fullver"
if [[ "$fullver" != "$basever" ]]; then if [[ "$fullver" != "$basever" ]]; then
printf "basever = %s\n" "$basever" write_kv_pair "basever" "$basever"
fi fi
# TODO: all fields should have this treatment # TODO: all fields should have this treatment
@ -634,43 +647,43 @@ write_pkginfo() {
spd=("${spd[@]#[[:space:]]}") spd=("${spd[@]#[[:space:]]}")
spd=("${spd[@]%[[:space:]]}") spd=("${spd[@]%[[:space:]]}")
printf "pkgdesc = %s\n" "$spd" write_kv_pair "pkgdesc" "$spd"
printf "url = %s\n" "$url" write_kv_pair "url" "$url"
printf "builddate = %s\n" "$builddate" write_kv_pair "builddate" "$builddate"
printf "packager = %s\n" "$packager" write_kv_pair "packager" "$packager"
printf "size = %s\n" "$size" write_kv_pair "size" "$size"
printf "arch = %s\n" "$pkgarch" write_kv_pair "arch" "$pkgarch"
mapfile -t provides < <(find_libprovides) mapfile -t provides < <(find_libprovides)
mapfile -t depends < <(find_libdepends) mapfile -t depends < <(find_libdepends)
[[ $license ]] && printf "license = %s\n" "${license[@]}" write_kv_pair "license" "${license[@]}"
[[ $replaces ]] && printf "replaces = %s\n" "${replaces[@]}" write_kv_pair "replaces" "${replaces[@]}"
[[ $groups ]] && printf "group = %s\n" "${groups[@]}" write_kv_pair "group" "${groups[@]}"
[[ $conflicts ]] && printf "conflict = %s\n" "${conflicts[@]}" write_kv_pair "conflict" "${conflicts[@]}"
[[ $provides ]] && printf "provides = %s\n" "${provides[@]}" write_kv_pair "provides" "${provides[@]}"
[[ $backup ]] && printf "backup = %s\n" "${backup[@]}" write_kv_pair "backup" "${backup[@]}"
[[ $depends ]] && printf "depend = %s\n" "${depends[@]}" write_kv_pair "depend" "${depends[@]}"
[[ $optdepends ]] && printf "optdepend = %s\n" "${optdepends[@]//+([[:space:]])/ }" write_kv_pair "optdepend" "${optdepends[@]//+([[:space:]])/ }"
[[ $makedepends ]] && printf "makedepend = %s\n" "${makedepends[@]}" write_kv_pair "makedepend" "${makedepends[@]}"
[[ $checkdepends ]] && printf "checkdepend = %s\n" "${checkdepends[@]}" write_kv_pair "checkdepend" "${checkdepends[@]}"
} }
write_buildinfo() { write_buildinfo() {
msg2 "$(gettext "Generating %s file...")" ".BUILDINFO" msg2 "$(gettext "Generating %s file...")" ".BUILDINFO"
printf "builddir = %s\n" "${BUILDDIR}" write_kv_pair "builddir" "${BUILDDIR}"
local sum="$(sha256sum "${BUILDFILE}")" local sum="$(sha256sum "${BUILDFILE}")"
sum=${sum%% *} sum=${sum%% *}
printf "pkgbuild_sha256sum = %s\n" $sum write_kv_pair "pkgbuild_sha256sum" $sum
printf "buildenv = %s\n" "${BUILDENV[@]}" write_kv_pair "buildenv" "${BUILDENV[@]}"
printf "options = %s\n" "${OPTIONS[@]}" write_kv_pair "options" "${OPTIONS[@]}"
local pkglist=($(run_pacman -Q | sed "s# #-#")) local pkglist=($(run_pacman -Q | sed "s# #-#"))
printf "installed = %s\n" "${pkglist[@]}" write_kv_pair "installed" "${pkglist[@]}"
} }
create_package() { create_package() {