Control: tags -1 patch

Gaudenz,

I know it has been a very long time. However, I have just reviewed and fixed the
quotation of variables within ucf. In particular, variables within command
substitutions need quoting separately[1]. This appears to resolve the issue of
spaces in ucf filenames.

My initial proposed patch is attached.

Mark

[1]  https://www.shellcheck.net/wiki/SC2086

>From 46c1d78f2e0bd10f09a22cd35d9e1b81b22aae8b Mon Sep 17 00:00:00 2001
From: Mark Hindley <m...@hindley.org.uk>
Date: Fri, 8 Nov 2024 20:03:37 +0000
Subject: [PATCH] ucf: fix quoting of variables (shellcheck SC2086).

Closes: #808277
---
 ucf | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/ucf b/ucf
index 4c896d8..dacbd77 100755
--- a/ucf
+++ b/ucf
@@ -36,7 +36,7 @@
 set -e
 
 # set the version and revision
-progname="$(basename $0)"
+progname="$(basename "$0")"
 pversion='Revision: 3.00 '
 
 unset GREP_OPTIONS
@@ -109,7 +109,7 @@ show_diff() {
     if [ -z "$1" ]; then
 	DIFF="There are no non-white space differences in the files."
     else
-        if  [ 99999 -lt "$(echo $1 | wc -c | awk '{print $1; }')" ]; then
+        if  [ 99999 -lt "$(echo "$1" | wc -c | awk '{print $1; }')" ]; then
             DIFF="The differences between the files are too large to display."
         else
             DIFF="$1"
@@ -286,7 +286,7 @@ replace_conf_file () {
     # or we have been ask to register
     real_file="$dest_file"
     if [ -L "$dest_file" ]; then
-	real_file="$(readlink -nf $dest_file || :)"
+	real_file="$(readlink -nf "$dest_file" || :)"
 	if [ "x$real_file" = "x" ]; then
 	    echo >&2 "$dest_file is a broken symlink!"
 	    $action rm -f "$dest_file";
@@ -412,7 +412,7 @@ if [ "X$PURGE" = "XYES" ]; then
     fi
     temp_dest_file="$1";
     if [ -e "$temp_dest_file" ]; then
-        setq dest_file "$(readlink -q -m $temp_dest_file)" "The Destination file";
+        setq dest_file "$(readlink -q -m "$temp_dest_file")" "The Destination file";
     else
         setq dest_file "$temp_dest_file" "The Destination file";
     fi
@@ -430,9 +430,9 @@ else
 	echo >&2 "Error: The new file ${temp_new_file} does not exist!";
 	exit 1;
     fi
-    setq new_file  "$(readlink -q -m $temp_new_file)"  "The new file";
+    setq new_file  "$(readlink -q -m "$temp_new_file")"  "The new file";
     if [ -e "$temp_dest_file" ]; then
-        setq dest_file "$(readlink -q -m $temp_dest_file)" "The Destination file";
+        setq dest_file "$(readlink -q -m "$temp_dest_file")" "The Destination file";
     else
         setq dest_file "$temp_dest_file" "The Destination file";
     fi
@@ -470,7 +470,7 @@ elif [ ! "x$conf_source_dir" = "x" ]; then
     setq source_dir "$conf_source_dir" "The Source directory"
 else
     if [ "X$new_file" != "X" ]; then
-	setq source_dir "$(dirname $new_file)" "The Source directory"
+	setq source_dir "$(dirname "$new_file")" "The Source directory"
     else
 	setq source_dir "/tmp" "The Source directory"
     fi
@@ -478,7 +478,7 @@ else
 fi
 
 if [ "X$PAGER" != "X" ] && which "$PAGER" >/dev/null 2>&1 ; then
-    my_pager="$(which $PAGER)";
+    my_pager="$(which "$PAGER")";
 elif [ -s /usr/bin/pager ] &&
      [ "X$(readlink -e /usr/bin/pager || :)" != "X" ]; then
     my_pager=/usr/bin/pager
@@ -542,7 +542,7 @@ elif [ ! "x$UCF_OLD_MDSUM_FILE" = "x" ]; then
 elif [ ! "x$conf_old_mdsum_file" = "x" ]; then
     setq old_mdsum_file "$conf_old_mdsum_file" "Replace the old file"
 elif [ ! "x${new_file}" = "x" ]; then
-    old_mdsum_file="$source_dir/$(basename ${new_file}).md5sum";
+    old_mdsum_file="$source_dir/$(basename "${new_file}").md5sum";
 else
     old_mdsum_file="";
 fi
@@ -594,7 +594,7 @@ else
     old_mdsum_dir="";
 fi
 
-cached_file="$(echo $dest_file | tr / :)"
+cached_file="$(echo "$dest_file" | tr / :)"
 ######################################################################
 ########                                                     #########
 ########                  Debugging dump                     #########
@@ -771,7 +771,7 @@ if [ -e "$dest_file" ]; then
 	if [ -d "$old_mdsum_dir" -o -f "$old_mdsum_file" ]; then
 	    if [ -d "$old_mdsum_dir"  ]; then
 		for file in ${old_mdsum_dir}/*; do
-		    oldsum="$(awk '{print $1}' $file)";
+		    oldsum="$(awk '{print $1}' "$file")";
 		    if [ "$oldsum" = "$destsum"  ]; then
 			if [ "X$force_conffold" = "X" ]; then
 #                           Bingo! replace, set the md5sum, and we are done
@@ -821,7 +821,7 @@ if [ -e "$dest_file" ]; then
 		    if [ "X$VERBOSE" != "X" ]; then
 			echo >&2 "However, a default entry exists, using it."
 		    fi
-		    lastsum="$(awk '{print $1;}' ${old_mdsum_dir}/default)"
+		    lastsum="$(awk '{print $1;}' "${old_mdsum_dir}"/default)"
 		    do_replace_md5sum=1;
 		fi
 	    elif [ -f "$old_mdsum_file" ]; then
@@ -962,7 +962,7 @@ else
 		fi
 		if [ "X$override_template" != "X" ]; then
 			choices="$(db_metaget $templ Choices-C)"
-			choices2="$(db_metaget $override_template Choices-C)"
+			choices2="$(db_metaget "$override_template" Choices-C)"
 			if [ "$choices" = "$choices2" ]; then
 				templ=$override_template
 			fi
@@ -971,7 +971,7 @@ else
 		db_reset "$templ"
 		db_subst "$templ" FILE "$dest_file"
 		db_subst "$templ" NEW  "$new_file"
-		db_subst "$templ" BASENAME "$(basename $dest_file)"
+		db_subst "$templ" BASENAME "$(basename "$dest_file")"
 		db_input critical "$templ" || true
 		if ! db_go; then
 			# The current ucf interface does not provide a way for it
-- 
2.39.5

Reply via email to