Просмотр исходного кода

libdpkg: Fix compress_cat to read/write to arbitrary fds

The compress_cat() code had a hidden assumption that fd_in is 0
and fd_out is 1. This is a bug waiting to happen. But luckily
all callers do use those values, so it is harmless.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Guillem Jover <guillem@debian.org>
Jonathan Nieder лет назад: 16
Родитель
Сommit
ade1c27e5c
1 измененных файлов с 4 добавлено и 4 удалено
  1. 4 4
      lib/dpkg/compress.c

+ 4 - 4
lib/dpkg/compress.c

@@ -151,8 +151,8 @@ compress_cat(enum compress_type type, int fd_in, int fd_out,
         gzFile gzfile;
         strncpy(combuf, "w9", sizeof(combuf));
         combuf[1]= *compression;
-        gzfile = gzdopen(1, combuf);
-        while((actualread = read(0,buffer,sizeof(buffer))) > 0) {
+        gzfile = gzdopen(fd_out, combuf);
+        while ((actualread = read(fd_in, buffer, sizeof(buffer))) > 0) {
           if (actualread < 0 ) {
             if (errno == EINTR) continue;
             ohshite(_("%s: internal gzip error: read: `%s'"), v.buf, strerror(errno));
@@ -186,8 +186,8 @@ compress_cat(enum compress_type type, int fd_in, int fd_out,
         BZFILE *bzfile;
         strncpy(combuf, "w9", sizeof(combuf));
         combuf[1]= *compression;
-        bzfile = BZ2_bzdopen(1, combuf);
-        while((actualread = read(0,buffer,sizeof(buffer))) > 0) {
+        bzfile = BZ2_bzdopen(fd_out, combuf);
+        while ((actualread = read(fd_in, buffer, sizeof(buffer))) > 0) {
           if (actualread < 0 ) {
             if (errno == EINTR) continue;
             ohshite(_("%s: internal bzip2 error: read: `%s'"), v.buf, strerror(errno));