From 0fa98479adc40435ac91d385354f7b372f9ae44e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 22 Jan 2014 19:49:02 +0100 Subject: db/upnp: obtain char* from ixmlwrap::getFirstElementValue() Fixes crash when there's no SearchCaps element. --- src/db/upnp/ContentDirectoryService.cxx | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/db/upnp/ContentDirectoryService.cxx b/src/db/upnp/ContentDirectoryService.cxx index b666716f7..d57f426ec 100644 --- a/src/db/upnp/ContentDirectoryService.cxx +++ b/src/db/upnp/ContentDirectoryService.cxx @@ -27,6 +27,7 @@ #include "Action.hxx" #include "util/Error.hxx" +#include #include ContentDirectoryService::ContentDirectoryService(const UPnPDevice &device, @@ -243,19 +244,22 @@ ContentDirectoryService::getSearchCapabilities(UpnpClient_Handle hdl, return false; } - std::string tbuf = ixmlwrap::getFirstElementValue(response, "SearchCaps"); - ixmlDocument_free(response); + const char *s = ixmlwrap::getFirstElementValue(response, "SearchCaps"); + if (s == nullptr || *s == 0) { + ixmlDocument_free(response); + return true; + } - if (!tbuf.compare("*")) { + bool success = true; + if (strcmp(s, "*") == 0) { result.insert(result.end(), "*"); - } else if (!tbuf.empty()) { - if (!csvToStrings(tbuf.c_str(), result)) { - error.Set(upnp_domain, "Bad response"); - return false; - } + } else if (!csvToStrings(s, result)) { + error.Set(upnp_domain, "Bad response"); + success = false; } - return true; + ixmlDocument_free(response); + return success; } bool -- cgit v1.2.3