Ver código fonte

pkg: Change directory to / before executing maintainer scripts

This should give maintainer scripts a more stable and sane environment.

This change does not work too well with relative admindir paths, as they
need to be normalized on input. But then several dpkg tools do not play
nice with relative amindirs anyway, and this needs a general cleanup
which will be done on subsequent commits.

Closes: #686782
Guillem Jover 14 anos atrás
pai
commit
7fb7f6e154
2 arquivos alterados com 5 adições e 2 exclusões
  1. 1 0
      debian/changelog
  2. 4 2
      src/script.c

+ 1 - 0
debian/changelog

@@ -68,6 +68,7 @@ dpkg (1.17.0) UNRELEASED; urgency=low
     when we are definitely removing the main path.
     when we are definitely removing the main path.
   * Activate file triggers on removal more accurately, only when we know
   * Activate file triggers on removal more accurately, only when we know
     we are inevitably removing things.
     we are inevitably removing things.
+  * Change dir to / before executing maintainer scripts. Closes: #686782
 
 
  -- Guillem Jover <guillem@debian.org>  Fri, 03 Aug 2012 13:21:00 +0200
  -- Guillem Jover <guillem@debian.org>  Fri, 03 Aug 2012 13:21:00 +0200
 
 

+ 4 - 2
src/script.c

@@ -118,9 +118,11 @@ preexecscript(struct command *cmd)
 
 
 		if (chroot(instdir))
 		if (chroot(instdir))
 			ohshite(_("failed to chroot to `%.250s'"), instdir);
 			ohshite(_("failed to chroot to `%.250s'"), instdir);
-		if (chdir("/"))
-			ohshite(_("failed to chdir to `%.255s'"), "/");
 	}
 	}
+	/* Switch to a known good directory to give the maintainer script
+	 * a saner environment, also needed after the chroot(). */
+	if (chdir("/"))
+		ohshite(_("failed to chdir to `%.255s'"), "/");
 	if (debug_has_flag(dbg_scripts)) {
 	if (debug_has_flag(dbg_scripts)) {
 		struct varbuf args = VARBUF_INIT;
 		struct varbuf args = VARBUF_INIT;
 		const char **argv = cmd->argv;
 		const char **argv = cmd->argv;