Ver código fonte

dpkg-maintscript-helper: Do safe matching of directories containing conffiles

By using a variable for the grep match we are exposed to metacharacters
acting as part of the regular expression.

Proposed-by: Carsten Hey <carsten@debian.org>
Guillem Jover 10 anos atrás
pai
commit
e981863071
2 arquivos alterados com 13 adições e 5 exclusões
  1. 4 0
      debian/changelog
  2. 9 5
      scripts/dpkg-maintscript-helper.sh

+ 4 - 0
debian/changelog

@@ -53,6 +53,10 @@ dpkg (1.18.5) UNRELEASED; urgency=medium
   * Make the Architecture field mandatory on package builds.
   * Use new Dpkg::Arch functions to validate and parse architectures when
     building source packages. Closes: #784808
+  * Do safe matching of directories containing conffiles in
+    dpkg-maintscript-helper, instead of using a variable pathname as a regex
+    with grep, which is susceptible to metacharacters acting as part of the
+    regex. Proposed by Carsten Hey <carsten@debian.org>.
   * Portability:
     - Move DPKG_ADMINDIR environment variable name out from update-alternatives
       code, to make life easier for non-dpkg-based systems.

+ 9 - 5
scripts/dpkg-maintscript-helper.sh

@@ -389,12 +389,16 @@ prepare_dir_to_symlink()
 	local PACKAGE="$1"
 	local PATHNAME="$2"
 
+	local LINE
 	# If there are conffiles we should not perform the switch.
-	if dpkg-query -W -f='${Conffiles}' "$PACKAGE" | \
-	   grep -q "^ $PATHNAME/."; then
-		error "directory '$PATHNAME' contains conffiles," \
-		      "cannot switch to symlink"
-	fi
+	dpkg-query -W -f='${Conffiles}\n' "$PACKAGE" | while read -r LINE; do
+		case "$LINE" in
+		"$PATHNAME"/*)
+			error "directory '$PATHNAME' contains conffiles," \
+			      "cannot switch to symlink"
+			;;
+		esac
+	done
 
 	# If there are locally created files or files owned by another package
 	# we should not perform the switch.