[libvirt] [PATCH] util: Prevent libvirtd crash

* src/util/virnetdevopenvswitch.c (virNetDevOpenvswitchAddPort): avoid libvirtd crash due to derefing a NULL virtVlan->tag. RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=852383 Signed-off-by: Alex Jia <ajia@redhat.com> --- src/util/virnetdevopenvswitch.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 601d79e..7d38ff8 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -100,7 +100,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virBufferAsprintf(buf, "%d", virtVlan->tag[i]); } } else { - virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]); + if (virtVlan->nTags) + virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]); } } -- 1.7.1

On 08/28/2012 04:28 AM, Alex Jia wrote:
* src/util/virnetdevopenvswitch.c (virNetDevOpenvswitchAddPort): avoid libvirtd crash due to derefing a NULL virtVlan->tag.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=852383
Signed-off-by: Alex Jia <ajia@redhat.com> --- src/util/virnetdevopenvswitch.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 601d79e..7d38ff8 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -100,7 +100,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virBufferAsprintf(buf, "%d", virtVlan->tag[i]); } } else { - virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]); + if (virtVlan->nTags)
You could avoid a level of indentation by using 'else if (virtVlan->nTags)' ACK. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Thanks for review, I will update it based on your advise, in addition, the commit message is very common, so also change it to "util: Prevent libvirtd crash from virNetDevOpenvswitchAddPort()", push now. -- Regards, Alex ----- Original Message ----- From: "Eric Blake" <eblake@redhat.com> To: "Alex Jia" <ajia@redhat.com> Cc: libvir-list@redhat.com Sent: Tuesday, August 28, 2012 11:25:02 PM Subject: Re: [libvirt] [PATCH] util: Prevent libvirtd crash On 08/28/2012 04:28 AM, Alex Jia wrote:
* src/util/virnetdevopenvswitch.c (virNetDevOpenvswitchAddPort): avoid libvirtd crash due to derefing a NULL virtVlan->tag.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=852383
Signed-off-by: Alex Jia <ajia@redhat.com> --- src/util/virnetdevopenvswitch.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 601d79e..7d38ff8 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -100,7 +100,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virBufferAsprintf(buf, "%d", virtVlan->tag[i]); } } else { - virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]); + if (virtVlan->nTags)
You could avoid a level of indentation by using 'else if (virtVlan->nTags)' ACK. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On 08/28/2012 07:28 AM, Alex Jia wrote:
* src/util/virnetdevopenvswitch.c (virNetDevOpenvswitchAddPort): avoid libvirtd crash due to derefing a NULL virtVlan->tag.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=852383
Signed-off-by: Alex Jia <ajia@redhat.com> --- src/util/virnetdevopenvswitch.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 601d79e..7d38ff8 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -100,7 +100,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virBufferAsprintf(buf, "%d", virtVlan->tag[i]); } } else { - virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]); + if (virtVlan->nTags) + virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]);
While this does eliminate the crash, it shouldn't have been necessary, and doesn't fix the root cause, which was a couple levels up in the callstack. The real problem is that &net->vlan was being sent, rather than virDomainNetGetActualVlan(net) (which returns NULL if the vlan info found has no tags). I've sent a separate patch to fix that (I should have caught it during review :-( ): https://www.redhat.com/archives/libvir-list/2012-August/msg01835.html

On 08/29/2012 06:45 PM, Laine Stump wrote:
* src/util/virnetdevopenvswitch.c (virNetDevOpenvswitchAddPort): avoid libvirtd crash due to derefing a NULL virtVlan->tag.
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=852383
Signed-off-by: Alex Jia<ajia@redhat.com> --- src/util/virnetdevopenvswitch.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 601d79e..7d38ff8 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -100,7 +100,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname, virBufferAsprintf(buf, "%d", virtVlan->tag[i]); } } else { - virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]); + if (virtVlan->nTags) + virBufferAsprintf(buf, "tag=%d", virtVlan->tag[0]); While this does eliminate the crash, it shouldn't have been necessary, and doesn't fix the root cause, which was a couple levels up in the callstack. The real problem is that&net->vlan was being sent, rather
On 08/28/2012 07:28 AM, Alex Jia wrote: than virDomainNetGetActualVlan(net) (which returns NULL if the vlan info found has no tags). I've sent a separate patch to fix that (I should have caught it during review :-( ):
https://www.redhat.com/archives/libvir-list/2012-August/msg01835.html
Yes, my patch hasn't resolved a root of issue, fortunately, you find and fix it :)
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (3)
-
Alex Jia
-
Eric Blake
-
Laine Stump