mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
test-tool: Don't call guestfs_set_qemu before guestfs handle is initialized (RHBZ#909836).
Because of evolution of the code, if the user used the --qemu or --qemudir options, libguestfs-test-tool would segfault because guestfs_set_qemu was being called before the guestfs handle was opened. Change the code so this doesn't happen, and also remove the global 'g' variable to make the code a bit more robust. Bug found by Amit Shah.
This commit is contained in:
@@ -44,10 +44,9 @@
|
||||
|
||||
static int timeout = DEFAULT_TIMEOUT;
|
||||
static char tmpf[] = P_tmpdir "/libguestfs-test-tool-sda-XXXXXX";
|
||||
static guestfs_h *g;
|
||||
|
||||
static void make_files (void);
|
||||
static void set_qemu (const char *path, int use_wrapper);
|
||||
static void set_qemu (guestfs_h *g, const char *path, int use_wrapper);
|
||||
|
||||
static void
|
||||
usage (void)
|
||||
@@ -91,6 +90,9 @@ main (int argc, char *argv[])
|
||||
int i;
|
||||
struct guestfs_version *vers;
|
||||
char *p;
|
||||
guestfs_h *g;
|
||||
char *qemu = NULL;
|
||||
int qemu_use_wrapper;
|
||||
|
||||
for (;;) {
|
||||
c = getopt_long (argc, argv, options, long_options, &option_index);
|
||||
@@ -98,10 +100,14 @@ main (int argc, char *argv[])
|
||||
|
||||
switch (c) {
|
||||
case 0: /* options which are long only */
|
||||
if (STREQ (long_options[option_index].name, "qemu"))
|
||||
set_qemu (optarg, 0);
|
||||
else if (STREQ (long_options[option_index].name, "qemudir"))
|
||||
set_qemu (optarg, 1);
|
||||
if (STREQ (long_options[option_index].name, "qemu")) {
|
||||
qemu = optarg;
|
||||
qemu_use_wrapper = 0;
|
||||
}
|
||||
else if (STREQ (long_options[option_index].name, "qemudir")) {
|
||||
qemu = optarg;
|
||||
qemu_use_wrapper = 1;
|
||||
}
|
||||
else {
|
||||
fprintf (stderr,
|
||||
_("libguestfs-test-tool: unknown long option: %s (%d)\n"),
|
||||
@@ -176,6 +182,9 @@ main (int argc, char *argv[])
|
||||
}
|
||||
guestfs_set_verbose (g, 1);
|
||||
|
||||
if (qemu)
|
||||
set_qemu (g, qemu, qemu_use_wrapper);
|
||||
|
||||
make_files ();
|
||||
|
||||
printf ("===== Test starts here =====\n");
|
||||
@@ -316,7 +325,7 @@ cleanup_wrapper (void)
|
||||
* a wrapper shell script.
|
||||
*/
|
||||
static void
|
||||
set_qemu (const char *path, int use_wrapper)
|
||||
set_qemu (guestfs_h *g, const char *path, int use_wrapper)
|
||||
{
|
||||
char *buffer;
|
||||
struct stat statbuf;
|
||||
|
||||
Reference in New Issue
Block a user