From dfbbc5e01a703bde9dac471e935537a5f724861b Mon Sep 17 00:00:00 2001 From: montellese Date: Thu, 24 Oct 2013 21:21:32 +0200 Subject: [PATCH] webserver: fix crash on HTTP GET arguments without a "=" (fixes #14650) --- xbmc/network/WebServer.cpp | 11 +++++++++-- xbmc/utils/StringUtils.cpp | 1 + xbmc/utils/StringUtils.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/xbmc/network/WebServer.cpp b/xbmc/network/WebServer.cpp index 4a0ea86819bf7..58c0e8e9d58a2 100644 --- a/xbmc/network/WebServer.cpp +++ b/xbmc/network/WebServer.cpp @@ -22,6 +22,7 @@ #ifdef HAS_WEB_SERVER #include "filesystem/File.h" #include "utils/log.h" +#include "utils/StringUtils.h" #include "utils/URIUtils.h" #include "utils/Variant.h" #include "utils/Base64.h" @@ -54,15 +55,21 @@ CWebServer::CWebServer() int CWebServer::FillArgumentMap(void *cls, enum MHD_ValueKind kind, const char *key, const char *value) { + if (cls == NULL || key == NULL) + return MHD_NO; + map *arguments = (map *)cls; - arguments->insert(pair(key,value)); + arguments->insert(pair(key, value != NULL ? value : StringUtils::Empty)); return MHD_YES; } int CWebServer::FillArgumentMultiMap(void *cls, enum MHD_ValueKind kind, const char *key, const char *value) { + if (cls == NULL || key == NULL) + return MHD_NO; + multimap *arguments = (multimap *)cls; - arguments->insert(pair(key,value)); + arguments->insert(pair(key, value != NULL ? value : StringUtils::Empty)); return MHD_YES; } diff --git a/xbmc/utils/StringUtils.cpp b/xbmc/utils/StringUtils.cpp index 51c7c78807221..b03a71c06f9c5 100644 --- a/xbmc/utils/StringUtils.cpp +++ b/xbmc/utils/StringUtils.cpp @@ -46,6 +46,7 @@ const char* ADDON_GUID_RE = "^(\\{){0,1}[0-9a-fA-F]{8}\\-[0-9a-fA-F]{4}\\-[0-9a- /* empty string for use in returns by ref */ const CStdString StringUtils::EmptyString = ""; +const std::string StringUtils::Empty = ""; CStdString StringUtils::m_lastUUID = ""; string StringUtils::Format(const char *fmt, ...) diff --git a/xbmc/utils/StringUtils.h b/xbmc/utils/StringUtils.h index 4b286dde7c60f..d1bac6bff1128 100644 --- a/xbmc/utils/StringUtils.h +++ b/xbmc/utils/StringUtils.h @@ -106,6 +106,7 @@ class StringUtils static bool IsInteger(const CStdString& str); static CStdString SizeToString(int64_t size); static const CStdString EmptyString; + static const std::string Empty; static size_t FindWords(const char *str, const char *wordLowerCase); static int FindEndBracket(const CStdString &str, char opener, char closer, int startPos = 0); static int DateStringToYYYYMMDD(const CStdString &dateString);