Richard W.M. Jones
2009-Nov-26 16:24 UTC
[Libguestfs] [PATCH] Fix error handling in 'zero' function.
The zero command is quite broken (along error paths). You must call reply_with_{,p}error along every error path. This patch fixes it. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html -------------- next part -------------->From 1a4c442a490f9ab0f5c9e3e8cb2dc6004d49d019 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Thu, 26 Nov 2009 16:06:03 +0000 Subject: [PATCH] Fix error handling in 'zero' function. --- daemon/zero.c | 17 +++++++---------- 1 files changed, 7 insertions(+), 10 deletions(-) diff --git a/daemon/zero.c b/daemon/zero.c index 0ade242..4d06505 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -41,20 +41,17 @@ do_zero (const char *device) memset (buf, 0, sizeof buf); - int err = 0; - int saved_errno = 0; for (i = 0; i < 32; ++i) if (write (fd, buf, sizeof buf) != sizeof buf) { - saved_errno = errno; - err = -1; + reply_with_perror ("write: %s", device); + close (fd); + return -1; } - if (close (fd) && saved_errno == 0) { - saved_errno = errno; - err = -1; + if (close (fd) == -1) { + reply_with_perror ("close: %s", device); + return -1; } - if (saved_errno) - errno = saved_errno; - return err; + return 0; } -- 1.6.5.2
Maybe Matching Threads
- [PATCH 0/10] Miscellaneous patches to fix some compile problems on Mac OS X
- [PATCH 0/9] FOR DISCUSSION ONLY: daemon error handling
- [PATCH 0/2] First part of fix for CVE-2010-3851
- [PATCH] Change handling of spaces on Linux kernel command line
- [PATCH 0/3] some guestfish sub commands can not handle special files properly (RHBZ#582484)