[libvirt] [PATCH] qemu: fix crash in migrate when migrateuri do not have a scheme

https://bugzilla.redhat.com/show_bug.cgi?id=1191355 When we migrate a vm with migrateuri option with a uri do not have scheme like this: # virsh migrate test4 --live qemu+ssh://lhuang/system --migrateuri 127.0.0.1 target libvirtd will crashed because uri->scheme is NULL in qemuMigrationPrepareDirect this line: if (STRNEQ(uri->scheme, "tcp") && add a value check before this line. Signed-off-by: Luyao Huang <lhuang@redhat.com> --- src/qemu/qemu_migration.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 879b1bf..5c3b73e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3281,6 +3281,13 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, if (!(uri = qemuMigrationParseURI(uri_in, &well_formed_uri))) goto cleanup; + if (uri->scheme == NULL) { + virReportError(VIR_ERR_INVALID_ARG, + _("missing scheme in migration URI: %s"), + uri_in); + goto cleanup; + } + if (STRNEQ(uri->scheme, "tcp") && STRNEQ(uri->scheme, "rdma")) { virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, -- 1.8.3.1

On 02/11/2015 03:41 PM, Luyao Huang wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1191355
When we migrate a vm with migrateuri option with a uri do not have scheme like this:
# virsh migrate test4 --live qemu+ssh://lhuang/system --migrateuri 127.0.0.1
target libvirtd will crashed because uri->scheme is NULL in qemuMigrationPrepareDirect this line:
if (STRNEQ(uri->scheme, "tcp") &&
add a value check before this line.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- src/qemu/qemu_migration.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 879b1bf..5c3b73e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3281,6 +3281,13 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, if (!(uri = qemuMigrationParseURI(uri_in, &well_formed_uri))) goto cleanup;
+ if (uri->scheme == NULL) { + virReportError(VIR_ERR_INVALID_ARG, + _("missing scheme in migration URI: %s"), + uri_in); + goto cleanup; + } + if (STRNEQ(uri->scheme, "tcp") && STRNEQ(uri->scheme, "rdma")) {
Why not just use "STRNEQ_NULLABLE" instead of "STRNEQ" directly? # git diff diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 879b1bf..baca2ed 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3281,8 +3281,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, if (!(uri = qemuMigrationParseURI(uri_in, &well_formed_uri))) goto cleanup; - if (STRNEQ(uri->scheme, "tcp") && - STRNEQ(uri->scheme, "rdma")) { + if (STRNEQ_NULLABLE(uri->scheme, "tcp") && + STRNEQ_NULLABLE(uri->scheme, "rdma")) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
-- Regards shyu

Error will be more clearly ;) BR, Luyao ----- Original Message ----- From: "Shanzhi Yu" <shyu@redhat.com> To: "Luyao Huang" <lhuang@redhat.com>, libvir-list@redhat.com Sent: Wednesday, February 11, 2015 3:50:37 PM Subject: Re: [libvirt] [PATCH] qemu: fix crash in migrate when migrateuri do not have a scheme On 02/11/2015 03:41 PM, Luyao Huang wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1191355
When we migrate a vm with migrateuri option with a uri do not have scheme like this:
# virsh migrate test4 --live qemu+ssh://lhuang/system --migrateuri 127.0.0.1
target libvirtd will crashed because uri->scheme is NULL in qemuMigrationPrepareDirect this line:
if (STRNEQ(uri->scheme, "tcp") &&
add a value check before this line.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- src/qemu/qemu_migration.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 879b1bf..5c3b73e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3281,6 +3281,13 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, if (!(uri = qemuMigrationParseURI(uri_in, &well_formed_uri))) goto cleanup;
+ if (uri->scheme == NULL) { + virReportError(VIR_ERR_INVALID_ARG, + _("missing scheme in migration URI: %s"), + uri_in); + goto cleanup; + } + if (STRNEQ(uri->scheme, "tcp") && STRNEQ(uri->scheme, "rdma")) {
Why not just use "STRNEQ_NULLABLE" instead of "STRNEQ" directly? # git diff diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 879b1bf..baca2ed 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3281,8 +3281,8 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, if (!(uri = qemuMigrationParseURI(uri_in, &well_formed_uri))) goto cleanup; - if (STRNEQ(uri->scheme, "tcp") && - STRNEQ(uri->scheme, "rdma")) { + if (STRNEQ_NULLABLE(uri->scheme, "tcp") && + STRNEQ_NULLABLE(uri->scheme, "rdma")) {
virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED,
-- Regards shyu

On Wed, Feb 11, 2015 at 03:50:37PM +0800, Shanzhi Yu wrote:
On 02/11/2015 03:41 PM, Luyao Huang wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1191355
When we migrate a vm with migrateuri option with a uri do not have scheme like this:
# virsh migrate test4 --live qemu+ssh://lhuang/system --migrateuri 127.0.0.1
target libvirtd will crashed because uri->scheme is NULL in qemuMigrationPrepareDirect this line:
if (STRNEQ(uri->scheme, "tcp") &&
There is a similar check in doNativeMigrate: if (!(uribits = qemuMigrationParseURI(uri, NULL))) return -1; if (STREQ(uribits->scheme, "rdma")) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATE_RDMA)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("outgoing RDMA migration is not supported " "with this QEMU binary")); It seems the scheme can be NULL here only if Prepare on the remote side returned a wrong URI, It would still be nice not to crash in that case.
add a value check before this line.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- src/qemu/qemu_migration.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 879b1bf..5c3b73e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3281,6 +3281,13 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, if (!(uri = qemuMigrationParseURI(uri_in, &well_formed_uri))) goto cleanup;
+ if (uri->scheme == NULL) { + virReportError(VIR_ERR_INVALID_ARG, + _("missing scheme in migration URI: %s"), + uri_in); + goto cleanup; + } + if (STRNEQ(uri->scheme, "tcp") && STRNEQ(uri->scheme, "rdma")) {
Why not just use "STRNEQ_NULLABLE" instead of "STRNEQ" directly?
It would report 'unsupported scheme (null) in migration URI:', instead of saying that the scheme is missing. Jan

On 02/11/2015 04:19 PM, Ján Tomko wrote:
On Wed, Feb 11, 2015 at 03:50:37PM +0800, Shanzhi Yu wrote:
On 02/11/2015 03:41 PM, Luyao Huang wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1191355
When we migrate a vm with migrateuri option with a uri do not have scheme like this:
# virsh migrate test4 --live qemu+ssh://lhuang/system --migrateuri 127.0.0.1
target libvirtd will crashed because uri->scheme is NULL in qemuMigrationPrepareDirect this line:
if (STRNEQ(uri->scheme, "tcp") && There is a similar check in doNativeMigrate:
if (!(uribits = qemuMigrationParseURI(uri, NULL))) return -1;
if (STREQ(uribits->scheme, "rdma")) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_MIGRATE_RDMA)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("outgoing RDMA migration is not supported " "with this QEMU binary"));
It seems the scheme can be NULL here only if Prepare on the remote side returned a wrong URI, It would still be nice not to crash in that case.
Thanks for pointing out and i will send a v2 later.
add a value check before this line.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- src/qemu/qemu_migration.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 879b1bf..5c3b73e 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -3281,6 +3281,13 @@ qemuMigrationPrepareDirect(virQEMUDriverPtr driver, if (!(uri = qemuMigrationParseURI(uri_in, &well_formed_uri))) goto cleanup;
+ if (uri->scheme == NULL) { + virReportError(VIR_ERR_INVALID_ARG, + _("missing scheme in migration URI: %s"), + uri_in); + goto cleanup; + } + if (STRNEQ(uri->scheme, "tcp") && STRNEQ(uri->scheme, "rdma")) { Why not just use "STRNEQ_NULLABLE" instead of "STRNEQ" directly?
It would report 'unsupported scheme (null) in migration URI:', instead of saying that the scheme is missing.
Jan
Luyao
participants (4)
-
Ján Tomko
-
lhuang
-
Luyao Huang
-
Shanzhi Yu