From 59b51274ebfce54ac9d384c05dc8c54b393107c0 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 8 Dec 2012 13:09:29 +0000 Subject: [PATCH] Check for error from some guestfs_set_* calls (found by Coverity). For some guestfs_set_* calls, add checks for error, when error might possibly occur. eg. It's plausible that guestfs_set_network might fail if the attach-method being used doesn't support it (although this doesn't happen at the moment). In other cases, don't check for errors, eg. if the error doesn't matter or there's nothing we could plausibly do about it. --- fish/fish.c | 6 ++++-- fuse/guestmount.c | 10 ++++++---- rescue/virt-rescue.c | 21 ++++++++++++++------- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/fish/fish.c b/fish/fish.c index 25e49c7e6..b24c49c7a 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -269,7 +269,8 @@ main (int argc, char *argv[]) } } } else if (STREQ (long_options[option_index].name, "selinux")) { - guestfs_set_selinux (g, 1); + if (guestfs_set_selinux (g, 1) == -1) + exit (EXIT_FAILURE); } else if (STREQ (long_options[option_index].name, "keys-from-stdin")) { keys_from_stdin = 1; } else if (STREQ (long_options[option_index].name, "progress-bars")) { @@ -290,7 +291,8 @@ main (int argc, char *argv[]) } else if (STREQ (long_options[option_index].name, "pipe-error")) { pipe_error = 1; } else if (STREQ (long_options[option_index].name, "network")) { - guestfs_set_network (g, 1); + if (guestfs_set_network (g, 1) == -1) + exit (EXIT_FAILURE); } else { fprintf (stderr, _("%s: unknown long option: %s (%d)\n"), program_name, long_options[option_index].name, option_index); diff --git a/fuse/guestmount.c b/fuse/guestmount.c index ec8439adb..3fa868de7 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -219,9 +219,10 @@ main (int argc, char *argv[]) dir_cache_timeout = atoi (optarg); else if (STREQ (long_options[option_index].name, "fuse-help")) fuse_help (); - else if (STREQ (long_options[option_index].name, "selinux")) - guestfs_set_selinux (g, 1); - else if (STREQ (long_options[option_index].name, "format")) { + else if (STREQ (long_options[option_index].name, "selinux")) { + if (guestfs_set_selinux (g, 1) == -1) + exit (EXIT_FAILURE); + } else if (STREQ (long_options[option_index].name, "format")) { if (!optarg || STREQ (optarg, "")) format = NULL; else @@ -357,7 +358,8 @@ main (int argc, char *argv[]) } /* If we're forking, we can't use the recovery process. */ - guestfs_set_recovery_proc (g, !do_fork); + if (guestfs_set_recovery_proc (g, !do_fork) == -1) + exit (EXIT_FAILURE); /* Do the guest drives and mountpoints. */ add_drives (drvs, 'a'); diff --git a/rescue/virt-rescue.c b/rescue/virt-rescue.c index c0e5f5620..5de47793d 100644 --- a/rescue/virt-rescue.c +++ b/rescue/virt-rescue.c @@ -156,7 +156,8 @@ main (int argc, char *argv[]) switch (c) { case 0: /* options which are long only */ if (STREQ (long_options[option_index].name, "selinux")) { - guestfs_set_selinux (g, 1); + if (guestfs_set_selinux (g, 1) == -1) + exit (EXIT_FAILURE); } else if (STREQ (long_options[option_index].name, "append")) { append = optarg; } else if (STREQ (long_options[option_index].name, "network")) { @@ -309,7 +310,8 @@ main (int argc, char *argv[]) usage (EXIT_FAILURE); /* Setting "direct mode" is required for the rescue appliance. */ - guestfs_set_direct (g, 1); + if (guestfs_set_direct (g, 1) == -1) + exit (EXIT_FAILURE); /* The libvirt backend doesn't support direct mode. As a temporary * workaround, force the appliance backend, but warn about it. @@ -321,18 +323,22 @@ main (int argc, char *argv[]) fprintf (stderr, _("%s: warning: virt-rescue doesn't work with the libvirt backend\n" "at the moment. As a workaround, forcing attach-method = 'appliance'.\n"), program_name); - guestfs_set_attach_method (g, "appliance"); + if (guestfs_set_attach_method (g, "appliance") == -1) + exit (EXIT_FAILURE); } free (attach_method); } /* Set other features. */ if (memsize > 0) - guestfs_set_memsize (g, memsize); + if (guestfs_set_memsize (g, memsize) == -1) + exit (EXIT_FAILURE); if (network) - guestfs_set_network (g, 1); + if (guestfs_set_network (g, 1) == -1) + exit (EXIT_FAILURE); if (smp >= 1) - guestfs_set_smp (g, smp); + if (guestfs_set_smp (g, smp) == -1) + exit (EXIT_FAILURE); /* Kernel command line must include guestfs_rescue=1 (see * appliance/init) as well as other options. @@ -340,7 +346,8 @@ main (int argc, char *argv[]) append_full = xasprintf ("guestfs_rescue=1%s%s", append ? " " : "", append ? append : ""); - guestfs_set_append (g, append_full); + if (guestfs_set_append (g, append_full) == -1) + exit (EXIT_FAILURE); free (append_full); /* Add drives. */