瀏覽代碼

do chdir("/") after chroot()

Michael Vogt 13 年之前
父節點
當前提交
2510eea4a0
共有 3 個文件被更改,包括 4 次插入4 次删除
  1. 1 1
      apt-pkg/aptconfiguration.cc
  2. 1 1
      apt-pkg/tagfile.cc
  3. 2 2
      cmdline/apt-mark.cc

+ 1 - 1
apt-pkg/aptconfiguration.cc

@@ -392,7 +392,7 @@ std::vector<std::string> const Configuration::getArchitectures(bool const &Cache
 			dup2(nullfd, STDIN_FILENO);
 			dup2(external[1], STDOUT_FILENO);
 			dup2(nullfd, STDERR_FILENO);
-			if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0)
+			if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0 && chdir("/") != 0)
 				_error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --print-foreign-architectures", chrootDir.c_str());
 			execvp(Args[0], (char**) &Args[0]);
 			_error->WarningE("getArchitecture", "Can't detect foreign architectures supported by dpkg!");

+ 1 - 1
apt-pkg/tagfile.cc

@@ -237,7 +237,7 @@ bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long long Offset)
 // ---------------------------------------------------------------------
 /* */
 pkgTagSection::pkgTagSection()
-   : Section(0), TagCount(0), Stop(0), d(NULL)
+   : Section(0), TagCount(0), d(NULL), Stop(0)
 {
    memset(&Indexes, 0, sizeof(Indexes));
    memset(&AlphaIndexes, 0, sizeof(AlphaIndexes));

+ 2 - 2
cmdline/apt-mark.cc

@@ -209,7 +209,7 @@ bool DoHold(CommandLine &CmdL)
       dup2(nullfd, STDIN_FILENO);
       dup2(nullfd, STDOUT_FILENO);
       dup2(nullfd, STDERR_FILENO);
-      if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0)
+      if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0 && chdir("/") != 0)
 	 _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --assert-multi-arch", chrootDir.c_str());
       execvp(Args[0], (char**) &Args[0]);
       _error->WarningE("dpkgGo", "Can't detect if dpkg supports multi-arch!");
@@ -279,7 +279,7 @@ bool DoHold(CommandLine &CmdL)
    {
       close(external[1]);
       std::string const chrootDir = _config->FindDir("DPkg::Chroot-Directory");
-      if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0)
+      if (chrootDir != "/" && chroot(chrootDir.c_str()) != 0 && chdir("/") != 0)
 	 _error->WarningE("getArchitecture", "Couldn't chroot into %s for dpkg --set-selections", chrootDir.c_str());
       int const nullfd = open("/dev/null", O_RDONLY);
       dup2(external[0], STDIN_FILENO);