[libvirt] [PATCH 2/2] xenParseXM: don't dereference NULL pointer when script is empty

O.k. to apply? -- Guido --- src/xenxs/xen_xm.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index d057043..30188e2 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -697,8 +697,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } } - if (bridge[0] || STREQ(script, "vif-bridge") || - STREQ(script, "vif-vnic")) { + if (bridge[0] || (script && (STREQ(script, "vif-bridge") || + STREQ(script, "vif-vnic")))) { net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; } else { net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; @@ -715,7 +715,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, !(net->data.bridge.ipaddr = strdup(ip))) goto no_memory; } else { - if (script[0] && + if (script && script[0] && !(net->data.ethernet.script = strdup(script))) goto no_memory; if (ip[0] && -- 1.7.6.3

On 06.10.2011 11:16, Guido Günther wrote:
O.k. to apply? -- Guido
--- src/xenxs/xen_xm.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index d057043..30188e2 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -697,8 +697,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } }
- if (bridge[0] || STREQ(script, "vif-bridge") || - STREQ(script, "vif-vnic")) { + if (bridge[0] || (script && (STREQ(script, "vif-bridge") ||
I'd rather use STREQ_NULLABLE here.

On Thu, Oct 06, 2011 at 11:56:29AM +0200, Michal Privoznik wrote:
On 06.10.2011 11:16, Guido Günther wrote:
O.k. to apply? -- Guido
--- src/xenxs/xen_xm.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index d057043..30188e2 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -697,8 +697,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } }
- if (bridge[0] || STREQ(script, "vif-bridge") || - STREQ(script, "vif-vnic")) { + if (bridge[0] || (script && (STREQ(script, "vif-bridge") ||
I'd rather use STREQ_NULLABLE here.
In fact I was looking for that kind of function in hacking.html. New patch attached. Cheers, -- Guido

On 10/06/2011 05:36 AM, Guido Günther wrote:
In fact I was looking for that kind of function in hacking.html. New patch attached. Cheers, -- Guido
0001-xenParseXM-don-t-dereference-NULL-pointer-when-scrip.patch
From 1819f18fbbf0c133a66c93debc117456e940b2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?=<agx@sigxcpu.org> Date: Thu, 6 Oct 2011 12:56:52 +0200 Subject: [PATCH] xenParseXM: don't dereference NULL pointer when script is empty
--- src/xenxs/xen_xm.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index d057043..6113f33 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -697,8 +697,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } }
- if (bridge[0] || STREQ(script, "vif-bridge") || - STREQ(script, "vif-vnic")) { + if (bridge[0] || STREQ_NULLABLE(script, "vif-bridge") || + STREQ_NULLABLE(script, "vif-vnic")) { net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; } else { net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; @@ -715,7 +715,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, !(net->data.bridge.ipaddr = strdup(ip))) goto no_memory; } else { - if (script[0]&& + if (script&& script[0]&& !(net->data.ethernet.script = strdup(script))) goto no_memory; if (ip[0]&& -- 1.7.6.3
ACK. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Thu, Oct 06, 2011 at 12:44:05PM -0600, Eric Blake wrote:
On 10/06/2011 05:36 AM, Guido Günther wrote:
In fact I was looking for that kind of function in hacking.html. New patch attached. Cheers, -- Guido
0001-xenParseXM-don-t-dereference-NULL-pointer-when-scrip.patch
From 1819f18fbbf0c133a66c93debc117456e940b2bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?=<agx@sigxcpu.org> Date: Thu, 6 Oct 2011 12:56:52 +0200 Subject: [PATCH] xenParseXM: don't dereference NULL pointer when script is empty
--- src/xenxs/xen_xm.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index d057043..6113f33 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -697,8 +697,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } }
- if (bridge[0] || STREQ(script, "vif-bridge") || - STREQ(script, "vif-vnic")) { + if (bridge[0] || STREQ_NULLABLE(script, "vif-bridge") || + STREQ_NULLABLE(script, "vif-vnic")) { net->type = VIR_DOMAIN_NET_TYPE_BRIDGE; } else { net->type = VIR_DOMAIN_NET_TYPE_ETHERNET; @@ -715,7 +715,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, !(net->data.bridge.ipaddr = strdup(ip))) goto no_memory; } else { - if (script[0]&& + if (script&& script[0]&& !(net->data.ethernet.script = strdup(script))) goto no_memory; if (ip[0]&& -- 1.7.6.3
ACK. Pushed. Thanks, -- Guido

On Thu, Oct 06, 2011 at 11:56:29AM +0200, Michal Privoznik wrote:
On 06.10.2011 11:16, Guido Günther wrote:
O.k. to apply? -- Guido
--- src/xenxs/xen_xm.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index d057043..30188e2 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -697,8 +697,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } }
- if (bridge[0] || STREQ(script, "vif-bridge") || - STREQ(script, "vif-vnic")) { + if (bridge[0] || (script && (STREQ(script, "vif-bridge") ||
I'd rather use STREQ_NULLABLE here. ...and here's the doc update. -- Guido

On 10/06/2011 05:38 AM, Guido Günther wrote:
...and here's the doc update. -- Guido
0001-Document-STREQ_NULLABLE-and-STRNEQ_NULLABLE.patch
From 07b8940e3bb64e2208b191d890e95f059a7ac7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?=<agx@sigxcpu.org> Date: Thu, 6 Oct 2011 13:32:49 +0200 Subject: [PATCH] Document STREQ_NULLABLE and STRNEQ_NULLABLE
--- docs/hacking.html.in | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 1a32d07..89f9980 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -587,6 +587,12 @@ STRPREFIX(a,b) </pre> </li> +<li><p>To avoid having to check if a or b are NULL:</p> +<pre> + STREQ_NULLABLE(a, b) + STRNEQ_NULLABLE(a, b) +</pre> +</li>
ACK. But be sure you also run 'make check', then squash in the regeneration of HACKING prior to pushing your commit. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Thu, Oct 06, 2011 at 08:27:42AM -0600, Eric Blake wrote:
On 10/06/2011 05:38 AM, Guido Günther wrote:
...and here's the doc update. -- Guido
0001-Document-STREQ_NULLABLE-and-STRNEQ_NULLABLE.patch
From 07b8940e3bb64e2208b191d890e95f059a7ac7a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?=<agx@sigxcpu.org> Date: Thu, 6 Oct 2011 13:32:49 +0200 Subject: [PATCH] Document STREQ_NULLABLE and STRNEQ_NULLABLE
--- docs/hacking.html.in | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 1a32d07..89f9980 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -587,6 +587,12 @@ STRPREFIX(a,b) </pre> </li> +<li><p>To avoid having to check if a or b are NULL:</p> +<pre> + STREQ_NULLABLE(a, b) + STRNEQ_NULLABLE(a, b) +</pre> +</li>
ACK. But be sure you also run 'make check', then squash in the regeneration of HACKING prior to pushing your commit.
I had to do a explicit "make HACKING" to get this regenerated. Pushed now - thanks. Cheers, -- Guido
-- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On 10/06/2011 08:52 AM, Guido Günther wrote:
ACK. But be sure you also run 'make check', then squash in the regeneration of HACKING prior to pushing your commit.
I had to do a explicit "make HACKING" to get this regenerated. Pushed now - thanks.
Ah, maybe it was only 'make syntax-check' that does the auto-regen. At any rate, thank you for the patch. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

On Thu, Oct 06, 2011 at 08:54:22AM -0600, Eric Blake wrote:
On 10/06/2011 08:52 AM, Guido Günther wrote:
ACK. But be sure you also run 'make check', then squash in the regeneration of HACKING prior to pushing your commit.
I had to do a explicit "make HACKING" to get this regenerated. Pushed now - thanks.
Ah, maybe it was only 'make syntax-check' that does the auto-regen. At any rate, thank you for the patch.
I checked and it's "make syntax-check". Thanks, -- Guido
participants (3)
-
Eric Blake
-
Guido Günther
-
Michal Privoznik