makepkg: protect against unexpected whitespace in filenames

zipman:

read -r protects against those evil manpages whose filenames contain
backslash escapes, (muahahaha?)

IFS= read protects against filenames with:

- leading whitespace (but no one is actually stupid enough to configure
  their MAN_DIRS=() in makepkg.conf with such silly directories, *right*?)

- trailing whitespace (but likewise, no one should be stupid enough to
  write an uncompressed manpage for section '1 ' or something)

Also fix several other cases where we read filenames without protecting
against surrounding whitespace, or without using null-delimited
filenames when we could trivially do so.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Eli Schwartz 2019-10-27 03:05:10 -04:00 committed by Allan McRae
parent 99639dc27c
commit a745d97c17
4 changed files with 11 additions and 11 deletions

View file

@ -34,7 +34,7 @@ tidy_staticlibs() {
if check_option "staticlibs" "n"; then if check_option "staticlibs" "n"; then
msg2 "$(gettext "Removing static library files...")" msg2 "$(gettext "Removing static library files...")"
local l local l
while read -rd '' l; do while IFS= read -rd '' l; do
if [[ -f "${l%.a}.so" || -h "${l%.a}.so" ]]; then if [[ -f "${l%.a}.so" || -h "${l%.a}.so" ]]; then
rm "$l" rm "$l"
fi fi

View file

@ -57,7 +57,7 @@ strip_file() {
# copy source files to debug directory # copy source files to debug directory
local f t local f t
while read -r t; do while IFS= read -r t; do
f=${t/${dbgsrcdir}/"$srcdir"} f=${t/${dbgsrcdir}/"$srcdir"}
mkdir -p "${dbgsrc/"$dbgsrcdir"/}${t%/*}" mkdir -p "${dbgsrc/"$dbgsrcdir"/}${t%/*}"
cp -- "$f" "${dbgsrc/"$dbgsrcdir"/}$t" cp -- "$f" "${dbgsrc/"$dbgsrcdir"/}$t"
@ -69,7 +69,7 @@ strip_file() {
objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary" objcopy --add-gnu-debuglink="$dbgdir/${binary#/}.debug" "$binary"
# create any needed hardlinks # create any needed hardlinks
while read -rd '' file ; do while IFS= read -rd '' file ; do
if [[ "${binary}" -ef "${file}" && ! -f "$dbgdir/${file}.debug" ]]; then if [[ "${binary}" -ef "${file}" && ! -f "$dbgdir/${file}.debug" ]]; then
mkdir -p "$dbgdir/${file%/*}" mkdir -p "$dbgdir/${file%/*}"
ln "$dbgdir/${binary}.debug" "$dbgdir/${file}.debug" ln "$dbgdir/${binary}.debug" "$dbgdir/${file}.debug"
@ -110,7 +110,7 @@ tidy_strip() {
fi fi
local binary strip_flags local binary strip_flags
find . -type f -perm -u+w -print0 2>/dev/null | while read -rd '' binary ; do find . -type f -perm -u+w -print0 2>/dev/null | while IFS= read -rd '' binary ; do
case "$(file -bi "$binary")" in case "$(file -bi "$binary")" in
*application/x-sharedlib*) # Libraries (.so) *application/x-sharedlib*) # Libraries (.so)
strip_flags="$STRIP_SHARED";; strip_flags="$STRIP_SHARED";;

View file

@ -35,9 +35,9 @@ tidy_zipman() {
msg2 "$(gettext "Compressing man and info pages...")" msg2 "$(gettext "Compressing man and info pages...")"
local file files inode link local file files inode link
while read -rd ' ' inode; do while read -rd ' ' inode; do
read file IFS= read -r file
find ${MAN_DIRS[@]} -type l 2>/dev/null | find "${MAN_DIRS[@]}" -type l -print0 2>/dev/null |
while read -r link ; do while IFS= read -rd '' link ; do
if [[ "${file}" -ef "${link}" ]] ; then if [[ "${file}" -ef "${link}" ]] ; then
rm -f "$link" "${link}.gz" rm -f "$link" "${link}.gz"
if [[ ${file%/*} = "${link%/*}" ]]; then if [[ ${file%/*} = "${link%/*}" ]]; then
@ -55,7 +55,7 @@ tidy_zipman() {
ln "${files[$inode]}.gz" "${file}.gz" ln "${files[$inode]}.gz" "${file}.gz"
chmod 644 "${file}.gz" chmod 644 "${file}.gz"
fi fi
done < <(find ${MAN_DIRS[@]} -type f \! -name "*.gz" \! -name "*.bz2" \ done < <(find "${MAN_DIRS[@]}" -type f \! -name "*.gz" \! -name "*.bz2" \
-exec @INODECMD@ '{}' + 2>/dev/null) -exec @INODECMD@ '{}' + 2>/dev/null)
fi fi
} }

View file

@ -474,7 +474,7 @@ find_libdepends() {
local libdeps filename soarch sofile soname soversion local libdeps filename soarch sofile soname soversion
declare -A libdeps declare -A libdeps
while read -r filename; do while IFS= read -rd '' filename; do
# get architecture of the file; if soarch is empty it's not an ELF binary # get architecture of the file; if soarch is empty it's not an ELF binary
soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p') soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
[[ -n "$soarch" ]] || continue [[ -n "$soarch" ]] || continue
@ -495,7 +495,7 @@ find_libdepends() {
libdeps[$soname]="${soversion}-${soarch}" libdeps[$soname]="${soversion}-${soarch}"
fi fi
done done
done < <(find "$pkgdir" -type f -perm -u+x) done < <(find "$pkgdir" -type f -perm -u+x -print0)
local libdepends v local libdepends v
for d in "${depends[@]}"; do for d in "${depends[@]}"; do
@ -1320,7 +1320,7 @@ if (( INFAKEROOT )); then
else else
run_split_packaging run_split_packaging
fi fi
create_debug_package create_debug_package
msg "$(gettext "Leaving %s environment.")" "fakeroot" msg "$(gettext "Leaving %s environment.")" "fakeroot"