From: Ian Campbell Subject: Re: [PATCH 02/21] libxc: Do not segfault if (e.g.) switch_qemu_logdirty fails Date: Thu, 21 Jun 2012 09:47:10 +0100 Message-ID: <1340268430.21872.14.camel@zakaz.uk.xensource.com> References: <1339761246-27641-1-git-send-email-ian.jackson@eu.citrix.com> <1339761246-27641-3-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1339761246-27641-3-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org On Fri, 2012-06-15 at 12:53 +0100, Ian Jackson wrote: > In xc_domain_save the local variable `ob' is initialised to NULL. > There are then various startup actions. Some of these `goto out' on > failure; for example the call to callbacks->switch_qemu_logdirty on > l.978. However, out is used both by success and error paths. So it > attempts (l.2043) to flush the current output buffer. If ob has not > yet been assigned a non-NULL value, this segfaults. So make the call > to outbuf_flush conditional on ob. > > Signed-off-by: Ian Jackson Doing anything like splitting the error case into a separate path etc looks too complex to me, so this seems like the best change. Acked-by: Ian Campbell I couldn't help noticing that there are a bunch of "goto out" statements _after_ the out label. They all appear to be protected by an if (!rc) and be preceded by an rc = 1, but talk about making it hard for the reader! > --- > tools/libxc/xc_domain_save.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/tools/libxc/xc_domain_save.c b/tools/libxc/xc_domain_save.c > index fcc7718..c359649 100644 > --- a/tools/libxc/xc_domain_save.c > +++ b/tools/libxc/xc_domain_save.c > @@ -2040,7 +2040,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iter > } > > /* Flush last write and discard cache for file. */ > - if ( outbuf_flush(xch, ob, io_fd) < 0 ) { > + if ( ob && outbuf_flush(xch, ob, io_fd) < 0 ) { > PERROR("Error when flushing output buffer"); > rc = 1; > }