[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH 18/15] 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>
---
 lib/dpkg/compression-backend.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/lib/dpkg/compression-backend.c b/lib/dpkg/compression-backend.c
index edd28b5..112b817 100644
--- a/lib/dpkg/compression-backend.c
+++ b/lib/dpkg/compression-backend.c
@@ -102,6 +102,8 @@ default_memlimit()
 	zFile zfile = zdopen(fd_in, "r"); \
 	\
 	while ((actualread = zread(zfile, buffer, sizeof(buffer)))) { \
+		int actualwrite; \
+		\
 		if (actualread < 0) { \
 			int err = 0; \
 			const char *errmsg = zerror(zfile, &err); \
@@ -111,7 +113,11 @@ default_memlimit()
 			ohshit(_("%s: internal " format " error: %s: %s"), \
 			       desc, "read", errmsg); \
 		} \
-		write(fd_out, buffer, actualread); \
+		\
+		actualwrite = write(fd_out, buffer, actualread); \
+		if (actualwrite != actualread) \
+			ohshite(_("%s: internal " format " error: %s"), \
+			        desc, "write"); \
 	} \
 	exit(0); \
 } while(0)
-- 
1.6.5.rc1.199.g596ec


Reply to: