makepkg: restrict pkgname and pkgver to ascii

pkgname and pkgver are used as directory names within database files.
libarchive does not provide a reliable locale-independent method for
reading archive file names, causing errors when archive paths include
non-ascii characters.

This is a first step toward dealing with FS#49342, by hopefully reducing
the number of packages with non-ascii data in the wild before updating
libalpm to reject them outright.

See https://github.com/libarchive/libarchive/wiki/Filenames
and https://github.com/libarchive/libarchive/issues/587

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 2019-06-03 00:32:35 -07:00 committed by Allan McRae
parent ff1ae94c10
commit 55a65aaf90
2 changed files with 9 additions and 0 deletions

View File

@ -45,6 +45,10 @@ lint_one_pkgname() {
error "$(gettext "%s is not allowed to start with a dot.")" "$type" error "$(gettext "%s is not allowed to start with a dot.")" "$type"
ret=1 ret=1
fi fi
if [[ $name = *[![:ascii:]]* ]]; then
error "$(gettext "%s may only contain ascii characters.")" "$type"
return 1
fi
if [[ $name = *[^[:alnum:]+_.@-]* ]]; then if [[ $name = *[^[:alnum:]+_.@-]* ]]; then
error "$(gettext "%s contains invalid characters: '%s'")" \ error "$(gettext "%s contains invalid characters: '%s'")" \
"$type" "${name//[[:alnum:]+_.@-]}" "$type" "${name//[[:alnum:]+_.@-]}"

View File

@ -41,6 +41,11 @@ check_pkgver() {
error "$(gettext "%s is not allowed to contain colons, forward slashes, hyphens or whitespace.")" "pkgver${type:+ in $type}" error "$(gettext "%s is not allowed to contain colons, forward slashes, hyphens or whitespace.")" "pkgver${type:+ in $type}"
return 1 return 1
fi fi
if [[ $ver = *[![:ascii:]]* ]]; then
error "$(gettext "%s may only contain ascii characters.")" "pkgver${type:+ in $type}"
return 1
fi
} }
lint_pkgver() { lint_pkgver() {