[fedora-virt] [PATCH] don't dereference or free undefined "msg" upon OOM

Richard W.M. Jones rjones at redhat.com
Wed Jul 1 14:23:20 UTC 2009


On Wed, Jul 01, 2009 at 04:08:33PM +0200, Jim Meyering wrote:
> Here's a tiny patch to prevent misbehavior on an OOM failure:
> I prefer the decl-after-stmt (c99) syntax, but if you're
> not assuming that already, just move the declaration of err "up".

I started off by declaring all the variables at the top of each
function, but after a while I got fed up with that, so a lot of the
code uses both styles ...

> >From bb57a823975019ab1be6f5f88e8276b53e8b4023 Mon Sep 17 00:00:00 2001
> From: Jim Meyering <meyering at redhat.com>
> Date: Wed, 1 Jul 2009 15:45:01 +0200
> Subject: [PATCH] don't dereference or free undefined "msg" upon OOM
> 
> * src/guestfs.c (guestfs_error): Handle failing vasprintf.
> ---
>  src/guestfs.c |    4 +++-
>  1 files changed, 3 insertions(+), 1 deletions(-)
> 
> diff --git a/src/guestfs.c b/src/guestfs.c
> index 5743a07..87b0d86 100644
> --- a/src/guestfs.c
> +++ b/src/guestfs.c
> @@ -404,9 +404,11 @@ guestfs_error (guestfs_h *g, const char *fs, ...)
>    char *msg;
> 
>    va_start (args, fs);
> -  vasprintf (&msg, fs, args);
> +  int err = vasprintf (&msg, fs, args);
>    va_end (args);
> 
> +  if (err < 0) return;
> +
>    if (g->error_cb) g->error_cb (g, g->error_cb_data, msg);
>    set_last_error (g, msg);
> 
> --
> 1.6.3.3.483.g4f5e

ACK.

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://et.redhat.com/~rjones/virt-df/




More information about the Fedora-virt mailing list