Przeglądaj źródła

libdpkg: Check for write errors during decompression

An unnoticed write error is unlikely to cause major problems,
since the process on the other end still has a chance to notice
the mangled stream. But it is worth fixing, especially because
the writing end can give a better error message.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Guillem Jover <guillem@debian.org>
Jonathan Nieder 16 lat temu
rodzic
commit
c482ae4999
1 zmienionych plików z 8 dodań i 4 usunięć
  1. 8 4
      lib/dpkg/compress.c

+ 8 - 4
lib/dpkg/compress.c

@@ -77,7 +77,7 @@ decompress_cat(enum compress_type type, int fd_in, int fd_out,
         gzFile gzfile = gzdopen(fd_in, "r");
 
         for (;;) {
-          int actualread;
+          int actualread, actualwrite;
 
           actualread = gzread(gzfile, buffer, sizeof(buffer));
           if (actualread < 0 ) {
@@ -91,7 +91,9 @@ decompress_cat(enum compress_type type, int fd_in, int fd_out,
           if (actualread == 0) /* EOF. */
             break;
 
-          write(fd_out,buffer,actualread);
+          actualwrite = write(fd_out, buffer, actualread);
+          if (actualwrite != actualread)
+            ohshite(_("%s: internal gzip write error"), desc);
         }
       }
       exit(0);
@@ -105,7 +107,7 @@ decompress_cat(enum compress_type type, int fd_in, int fd_out,
         BZFILE *bzfile = BZ2_bzdopen(fd_in, "r");
 
         for (;;) {
-          int actualread;
+          int actualread, actualwrite;
 
           actualread = BZ2_bzread(bzfile, buffer, sizeof(buffer));
           if (actualread < 0 ) {
@@ -119,7 +121,9 @@ decompress_cat(enum compress_type type, int fd_in, int fd_out,
           if (actualread == 0) /* EOF. */
             break;
 
-          write(fd_out,buffer,actualread);
+          actualwrite = write(fd_out, buffer, actualread);
+          if (actualwrite != actualread)
+            ohshite(_("%s: internal bzip2 write error"), desc);
         }
       }
       exit(0);