[Libguestfs] [PATCH 1/3] launch: move the filename checking to a wrapper

Richard W.M. Jones rjones at redhat.com
Mon Jan 9 10:22:56 UTC 2012


On Mon, Jan 09, 2012 at 03:22:41PM +0800, Wanlong Gao wrote:
> Move the filename's comma character checking to a wrapper.
> 
> Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
> ---
>  src/launch.c |   18 ++++++++++++------
>  1 files changed, 12 insertions(+), 6 deletions(-)
> 
> diff --git a/src/launch.c b/src/launch.c
> index ca89b63..8eaaac8 100644
> --- a/src/launch.c
> +++ b/src/launch.c
> @@ -277,6 +277,16 @@ valid_format_iface (const char *str)
>    return 1;
>  }
>  
> +static int
> +check_path (guestfs_h *g, const char *filename)
> +{
> +  if (strchr (filename, ',') != NULL) {
> +    error (g, _("filename cannot contain ',' (comma) character"));
> +    return 1;

Almost every checking function like this returns -1 on error (and
0 for OK).

> +  }
> +  return 0;
> +}
> +
>  int
>  guestfs__add_drive_opts (guestfs_h *g, const char *filename,
>                           const struct guestfs_add_drive_opts_argv *optargs)
> @@ -287,10 +297,8 @@ guestfs__add_drive_opts (guestfs_h *g, const char *filename,
>    char *name;
>    int use_cache_off;
>  
> -  if (strchr (filename, ',') != NULL) {
> -    error (g, _("filename cannot contain ',' (comma) character"));
> +  if (check_path(g, filename))

So this would have to change also to:

  if (check_path (g, filename) == -1)

>      return -1;
> -  }
>  
>    readonly = optargs->bitmask & GUESTFS_ADD_DRIVE_OPTS_READONLY_BITMASK
>               ? optargs->readonly : 0;
> @@ -405,10 +413,8 @@ guestfs__add_drive_ro_with_if (guestfs_h *g, const char *filename,
>  int
>  guestfs__add_cdrom (guestfs_h *g, const char *filename)
>  {
> -  if (strchr (filename, ',') != NULL) {
> -    error (g, _("filename cannot contain ',' (comma) character"));
> +  if (check_path(g, filename))
>      return -1;
> -  }
>  
>    if (access (filename, F_OK) == -1) {
>      perrorf (g, "%s", filename);
> -- 
> 1.7.8

But basically this patch is fine.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v




More information about the Libguestfs mailing list