Prechádzať zdrojové kódy

libdpkg: Reset environment variables for all compressors in the filter

This makes sure the commands will not produce strange output due to
environment settings. The cleaned environment variables are XZ_DEFAULTS,
XZ_OPT, BZIP and BZIP2, depending on the compressor used.

Move GZIP environment variable cleanup to libdpkg, as there's nothing
inherently dpkg-deb specific in resetting the environment variables for
a specific compressor so that the output is reproducible and a bit more
consistent with the code using the specific compressor library.
Guillem Jover 13 rokov pred
rodič
commit
2fa8794747
3 zmenil súbory, kde vykonal 23 pridanie a 11 odobranie
  1. 3 0
      debian/changelog
  2. 0 2
      dpkg-deb/main.c
  3. 20 9
      lib/dpkg/compress.c

+ 3 - 0
debian/changelog

@@ -57,6 +57,9 @@ dpkg (1.17.2) UNRELEASED; urgency=low
   * Do not store timestamps in gzip headers when using the command, to try to
     mimic the zlib behavior. This does not affect Debian as it's been using
     zlib for a very long time. Closes: #719844
+  * Reset environment variables affecting compressor commands when not using
+    the shared library implementations. Namely XZ_DEFAULTS, XZ_OPT, BZIP and
+    BZIP2.
 
   [ Updated programs translations ]
   * German (Sven Joachim).

+ 0 - 2
dpkg-deb/main.c

@@ -264,8 +264,6 @@ int main(int argc, const char *const *argv) {
   if (!compressor_check_params(&compress_params, &err))
     badusage(_("invalid compressor parameters: %s"), err.str);
 
-  unsetenv("GZIP");
-
   ret = cipaction->action(argv);
 
   dpkg_program_done();

+ 20 - 9
lib/dpkg/compress.c

@@ -51,11 +51,13 @@
 #include <dpkg/subproc.h>
 
 static void DPKG_ATTR_SENTINEL
-fd_fd_filter(int fd_in, int fd_out, const char *desc, const char *file, ...)
+fd_fd_filter(int fd_in, int fd_out, const char *desc, const char *delenv[],
+             const char *file, ...)
 {
 	va_list args;
 	struct command cmd;
 	pid_t pid;
+	int i;
 
 	pid = subproc_fork();
 	if (pid == 0) {
@@ -68,6 +70,9 @@ fd_fd_filter(int fd_in, int fd_out, const char *desc, const char *file, ...)
 			close(fd_out);
 		}
 
+		for (i = 0; delenv[i]; i++)
+			unsetenv(delenv[i]);
+
 		command_init(&cmd, file, desc);
 		command_add_arg(&cmd, file);
 		va_start(args, file);
@@ -232,10 +237,12 @@ compress_gzip(int fd_in, int fd_out, struct compress_params *params, const char
 	}
 }
 #else
+static const char *env_gzip[] = { "GZIP", NULL };
+
 static void
 decompress_gzip(int fd_in, int fd_out, const char *desc)
 {
-	fd_fd_filter(fd_in, fd_out, desc, GZIP, "-dc", NULL);
+	fd_fd_filter(fd_in, fd_out, desc, env_gzip, GZIP, "-dc", NULL);
 }
 
 static void
@@ -244,7 +251,7 @@ compress_gzip(int fd_in, int fd_out, struct compress_params *params, const char
 	char combuf[6];
 
 	snprintf(combuf, sizeof(combuf), "-c%d", params->level);
-	fd_fd_filter(fd_in, fd_out, desc, GZIP, "-n", combuf, NULL);
+	fd_fd_filter(fd_in, fd_out, desc, env_gzip, GZIP, "-n", combuf, NULL);
 }
 #endif
 
@@ -356,10 +363,12 @@ compress_bzip2(int fd_in, int fd_out, struct compress_params *params, const char
 		ohshite(_("%s: internal bzip2 write error"), desc);
 }
 #else
+static const char *env_bzip2[] = { "BZIP", "BZIP2", NULL };
+
 static void
 decompress_bzip2(int fd_in, int fd_out, const char *desc)
 {
-	fd_fd_filter(fd_in, fd_out, desc, BZIP2, "-dc", NULL);
+	fd_fd_filter(fd_in, fd_out, desc, env_bzip2, BZIP2, "-dc", NULL);
 }
 
 static void
@@ -368,7 +377,7 @@ compress_bzip2(int fd_in, int fd_out, struct compress_params *params, const char
 	char combuf[6];
 
 	snprintf(combuf, sizeof(combuf), "-c%d", params->level);
-	fd_fd_filter(fd_in, fd_out, desc, BZIP2, combuf, NULL);
+	fd_fd_filter(fd_in, fd_out, desc, env_bzip2, BZIP2, combuf, NULL);
 }
 #endif
 
@@ -575,10 +584,12 @@ compress_xz(int fd_in, int fd_out, struct compress_params *params, const char *d
 	filter_lzma(&io, fd_in, fd_out);
 }
 #else
+static const char *env_xz[] = { "XZ_DEFAULTS", "XZ_OPT", NULL };
+
 static void
 decompress_xz(int fd_in, int fd_out, const char *desc)
 {
-	fd_fd_filter(fd_in, fd_out, desc, XZ, "-dc", NULL);
+	fd_fd_filter(fd_in, fd_out, desc, env_xz, XZ, "-dc", NULL);
 }
 
 static void
@@ -593,7 +604,7 @@ compress_xz(int fd_in, int fd_out, struct compress_params *params, const char *d
 		strategy = NULL;
 
 	snprintf(combuf, sizeof(combuf), "-c%d", params->level);
-	fd_fd_filter(fd_in, fd_out, desc, XZ, combuf, strategy, NULL);
+	fd_fd_filter(fd_in, fd_out, desc, env_xz, XZ, combuf, strategy, NULL);
 }
 #endif
 
@@ -674,7 +685,7 @@ compress_lzma(int fd_in, int fd_out, struct compress_params *params, const char
 static void
 decompress_lzma(int fd_in, int fd_out, const char *desc)
 {
-	fd_fd_filter(fd_in, fd_out, desc, XZ, "-dc", "--format=lzma", NULL);
+	fd_fd_filter(fd_in, fd_out, desc, env_xz, XZ, "-dc", "--format=lzma", NULL);
 }
 
 static void
@@ -683,7 +694,7 @@ compress_lzma(int fd_in, int fd_out, struct compress_params *params, const char
 	char combuf[6];
 
 	snprintf(combuf, sizeof(combuf), "-c%d", params->level);
-	fd_fd_filter(fd_in, fd_out, desc, XZ, combuf, "--format=lzma", NULL);
+	fd_fd_filter(fd_in, fd_out, desc, env_xz, XZ, combuf, "--format=lzma", NULL);
 }
 #endif