[libvirt] [PATCH] Fix segfault if storage pool has no type attribute (possibly others)

virEnumFromString doesn't check for a NULL string, and will segfault if passed one. Lots of calling code protects against this, but at least /pool/@type parsing does not. Signed-off-by: Cole Robinson <crobinso@redhat.com> --- src/util.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/src/util.c b/src/util.c index d8ab37f..8b746f5 100644 --- a/src/util.c +++ b/src/util.c @@ -1622,6 +1622,9 @@ int virEnumFromString(const char *const*types, const char *type) { unsigned int i; + if (!type) + return -1; + for (i = 0 ; i < ntypes ; i++) if (STREQ(types[i], type)) return i; -- 1.6.3.2

On Fri, Jun 19, 2009 at 12:36:51PM -0400, Cole Robinson wrote:
virEnumFromString doesn't check for a NULL string, and will segfault if passed one. Lots of calling code protects against this, but at least /pool/@type parsing does not.
Agreed, ACK Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On Fri, Jun 19, 2009 at 12:36:51PM -0400, Cole Robinson wrote:
virEnumFromString doesn't check for a NULL string, and will segfault if passed one. Lots of calling code protects against this, but at least /pool/@type parsing does not.
Signed-off-by: Cole Robinson <crobinso@redhat.com> --- src/util.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
ACK, don't really know why it wasn't doing this already Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
participants (3)
-
Cole Robinson
-
Daniel P. Berrange
-
Daniel Veillard