From 99765c58281cf79d9b27576c80483b868d1d73c5 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 19 Jan 2023 10:13:25 -0700 Subject: hstow: readlinks: check link targets for control chars --- bin/hstow | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'bin/hstow') diff --git a/bin/hstow b/bin/hstow index 3fce0a72..7aba04de 100755 --- a/bin/hstow +++ b/bin/hstow @@ -53,11 +53,19 @@ fi # Here we unconditionally bypass readlink(1), for speed. # The long regexp is because only BREs have backreferences in POSIX. readlinks () { - local restc=$1 assume="${2:-false}" first= rest= + local restc=$1 assume="${2:-false}" first= rest= ls= while read -r first rest; do if $assume || [ -h "$first" ]; then - [ -n "$rest" ] && rest="$rest$tab" - rest="$rest$(ls -ld "$first")" + ls="$(ls -ld "$first")" + case "$ls" in + $cchars) + printf \ + 'hstow: skipping %s due to control chars in link target\n' \ + "$first" >&2 + continue + ;; + esac + [ -n "$rest" ] && rest="$rest$tab$ls" || rest=$ls fi printf '%s\t%s\n' "$first" "$rest" done | sed 's/^\([^\t]\{1,\}\)\t\('\ -- cgit v1.2.3