qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: qemu-devel@nongnu.org
Cc: Peter Lieven <pl@kamp.de>
Subject: [Qemu-devel] [PATCH 2/2] vl.c: fix segfault in iscsi options parsing
Date: Tue, 19 Mar 2013 09:19:18 +0100	[thread overview]
Message-ID: <1363681158-26122-3-git-send-email-pl@kamp.de> (raw)
In-Reply-To: <1363681158-26122-1-git-send-email-pl@kamp.de>

this patch fixes parsing of iscsi options such as initiator-name
passed to command line via -iscsi option group.

because iscsi options where registered too late qemu_find_opts
returned NULL leading to a segfault in qemu_opts_parse.

Signed-off-by: Peter Lieven <pl@kamp.de>
---
 block/iscsi.c |   27 ---------------------------
 vl.c          |   40 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 37 insertions(+), 30 deletions(-)

diff --git a/block/iscsi.c b/block/iscsi.c
index 3d52921..23d4210 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1263,36 +1263,9 @@ static BlockDriver bdrv_iscsi = {
 #endif
 };
 
-static QemuOptsList qemu_iscsi_opts = {
-    .name = "iscsi",
-    .head = QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts.head),
-    .desc = {
-        {
-            .name = "user",
-            .type = QEMU_OPT_STRING,
-            .help = "username for CHAP authentication to target",
-        },{
-            .name = "password",
-            .type = QEMU_OPT_STRING,
-            .help = "password for CHAP authentication to target",
-        },{
-            .name = "header-digest",
-            .type = QEMU_OPT_STRING,
-            .help = "HeaderDigest setting. "
-                    "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
-        },{
-            .name = "initiator-name",
-            .type = QEMU_OPT_STRING,
-            .help = "Initiator iqn name to use when connecting",
-        },
-        { /* end of list */ }
-    },
-};
-
 static void iscsi_block_init(void)
 {
     bdrv_register(&bdrv_iscsi);
-    qemu_add_opts(&qemu_iscsi_opts);
 }
 
 block_init(iscsi_block_init);
diff --git a/vl.c b/vl.c
index ce51e65..9925675 100644
--- a/vl.c
+++ b/vl.c
@@ -517,6 +517,34 @@ static QemuOptsList qemu_tpmdev_opts = {
     },
 };
 
+#ifdef CONFIG_LIBISCSI
+static QemuOptsList qemu_iscsi_opts = {
+    .name = "iscsi",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_iscsi_opts.head),
+    .desc = {
+        {
+            .name = "user",
+            .type = QEMU_OPT_STRING,
+            .help = "username for CHAP authentication to target",
+        },{
+            .name = "password",
+            .type = QEMU_OPT_STRING,
+            .help = "password for CHAP authentication to target",
+        },{
+            .name = "header-digest",
+            .type = QEMU_OPT_STRING,
+            .help = "HeaderDigest setting. "
+                    "{CRC32C|CRC32C-NONE|NONE-CRC32C|NONE}",
+        },{
+            .name = "initiator-name",
+            .type = QEMU_OPT_STRING,
+            .help = "Initiator iqn name to use when connecting",
+        },
+        { /* end of list */ }
+    },
+};
+#endif
+
 const char *qemu_get_vm_name(void)
 {
     return qemu_name;
@@ -2899,6 +2927,9 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_add_fd_opts);
     qemu_add_opts(&qemu_object_opts);
     qemu_add_opts(&qemu_tpmdev_opts);
+#ifdef CONFIG_LIBISCSI
+    qemu_add_opts(&qemu_iscsi_opts);
+#endif
 
     runstate_init();
 
@@ -3199,14 +3230,17 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
-#ifdef CONFIG_LIBISCSI
             case QEMU_OPTION_iscsi:
-                opts = qemu_opts_parse(qemu_find_opts("iscsi"), optarg, 0);
+                olist = qemu_find_opts("iscsi");
+                if (!olist) {
+                    fprintf(stderr, "iscsi is not supported by this qemu build.\n");
+                    exit(1);
+                }
+                opts = qemu_opts_parse(olist, optarg, 0);
                 if (!opts) {
                     exit(1);
                 }
                 break;
-#endif
 #ifdef CONFIG_SLIRP
             case QEMU_OPTION_tftp:
                 legacy_tftp_prefix = optarg;
-- 
1.7.9.5

  parent reply	other threads:[~2013-03-19  8:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-19  8:19 [Qemu-devel] [PATCH 0/2] fix segfault in (iscsi) option parsing Peter Lieven
2013-03-19  8:19 ` [Qemu-devel] [PATCH 1/2] qemu-option: avoid segfault if QemuOptsList == NULL Peter Lieven
2013-03-19  8:19 ` Peter Lieven [this message]
2013-03-19  8:51 ` [Qemu-devel] [PATCH 0/2] fix segfault in (iscsi) option parsing Markus Armbruster
2013-03-19 11:18   ` Paolo Bonzini
2013-03-19 15:54     ` Peter Lieven
2013-03-19 17:07       ` Paolo Bonzini
2013-03-19 19:37         ` Peter Lieven
2013-03-19 20:58           ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1363681158-26122-3-git-send-email-pl@kamp.de \
    --to=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).