Procházet zdrojové kódy

dpkg-maintscript-helper: Make conffile commands more robust

Check that conffile pathname arguments are absolute paths. Verify
version number to be valid.

[guillem@debian.org:
 - reword error messages.
 - add a comment explaining the --compare-versions usage.
 - use 0 instead of 1-1 as dummy version number. ]

Signed-off-by: Guillem Jover <guillem@debian.org>
David Kalnischkies před 10 roky
rodič
revize
cb0a2b1ef2
2 změnil soubory, kde provedl 15 přidání a 0 odebrání
  1. 3 0
      debian/changelog
  2. 12 0
      scripts/dpkg-maintscript-helper.sh

+ 3 - 0
debian/changelog

@@ -1,6 +1,9 @@
 dpkg (1.18.11) UNRELEASED; urgency=medium
 
   [ Guillem Jover ]
+  * Make dpkg-maintscript-helper conffile commands more robust. Check that
+    conffile pathname arguments are absolute paths and verify version number
+    to be valid. Thanks to David Kalnischkies <david@kalnischkies.de>.
   * Packaging:
     - Add liblocale-gettext-perl to libdpkg-perl Recommends.
     - Wrap and document dependency relationships.

+ 12 - 0
scripts/dpkg-maintscript-helper.sh

@@ -46,6 +46,11 @@ rm_conffile() {
 	[ -n "$1" ] || error "maintainer script parameters are missing"
 	[ -n "$DPKG_MAINTSCRIPT_NAME" ] || \
 		error "environment variable DPKG_MAINTSCRIPT_NAME is required"
+	[ "${CONFFILE}" != "${CONFFILE#/}" ] || \
+		error "conffile '$CONFFILE' is not an absolute path"
+	# Use --compare-versions to validate the version number.
+	[ -z "$(dpkg --compare-versions -- "$LASTVERSION" eq '0' 2>&1)" ] || \
+		error "version '$LASTVERSION' is not valid"
 
 	debug "Executing $0 rm_conffile in $DPKG_MAINTSCRIPT_NAME" \
 	      "of $DPKG_MAINTSCRIPT_PACKAGE"
@@ -153,6 +158,13 @@ mv_conffile() {
 	[ -n "$1" ] || error "maintainer script parameters are missing"
 	[ -n "$DPKG_MAINTSCRIPT_NAME" ] || \
 		error "environment variable DPKG_MAINTSCRIPT_NAME is required"
+	[ "${OLDCONFFILE}" != "${OLDCONFFILE#/}" ] || \
+		error "old-conffile '$OLDCONFFILE' is not an absolute path"
+	[ "${NEWCONFFILE}" != "${NEWCONFFILE#/}" ] || \
+		error "new-conffile '$NEWCONFFILE' is not an absolute path"
+	# Use --compare-versions to validate the version number.
+	[ -z "$(dpkg --compare-versions -- "$LASTVERSION" eq '0' 2>&1)" ] || \
+		error "version '$LASTVERSION' is not valid"
 
 	debug "Executing $0 mv_conffile in $DPKG_MAINTSCRIPT_NAME" \
 	      "of $DPKG_MAINTSCRIPT_PACKAGE"