1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-18 02:19:39 +00:00

safe_dot check file is a file

Since we are being paranoid, check that each arg to safe_dot is
actually a file as well as non-empty.

Check for white-space in filenames - these require special handling.
This commit is contained in:
Simon J. Gerraty 2024-08-16 13:15:20 -07:00
parent 5685098846
commit 35399f68c8

View File

@ -1,7 +1,7 @@
# SPDX-License-Identifier: BSD-2-Clause
# RCSid:
# $Id: safe_eval.sh,v 1.16 2024/08/15 02:28:30 sjg Exp $
# $Id: safe_eval.sh,v 1.20 2024/08/16 00:57:58 sjg Exp $
#
# @(#) Copyright (c) 2023-2024 Simon J. Gerraty
#
@ -54,9 +54,10 @@ safe_eval_export() {
# feed all "file" that exist to safe_eval
#
safe_dot() {
eval ${local:-:} ef ex f
eval ${local:-:} ef ex f rc
ef=
ex=
rc=1
while :
do
case "$1" in
@ -66,11 +67,20 @@ safe_dot() {
done
for f in "$@"
do
test -s $f || continue
test -s "$f" -a -f "$f" || continue
: check for space or tab in "$f"
case "$f" in
*[[:space:]]*|*" "*|*" "*) # we cannot do this efficiently
dotted="$dotted $f"
safe_eval$ex "$f"
rc=$?
continue
;;
esac
ef="${ef:+$ef }$f"
dotted="$dotted $f"
done
test -z "$ef" && return 1
test -z "$ef" && return $rc
safe_eval$ex $ef
return 0
}