From 8399af9268e8d55c1f3147acbcecb910431bc717 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 9 Jun 2017 12:45:39 -0300 Subject: [PATCH] Fix crash in case that the news RSS is malformed --- src/app/ui/news_listbox.cpp | 41 +++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/app/ui/news_listbox.cpp b/src/app/ui/news_listbox.cpp index 6ee2ae2a8..dfcf330bc 100644 --- a/src/app/ui/news_listbox.cpp +++ b/src/app/ui/news_listbox.cpp @@ -273,36 +273,37 @@ void NewsListBox::parseFile(const std::string& filename) TiXmlElement* titleXml = itemXml->FirstChildElement("title"); TiXmlElement* descXml = itemXml->FirstChildElement("description"); TiXmlElement* linkXml = itemXml->FirstChildElement("link"); + if (titleXml && titleXml->GetText() && + descXml && descXml->GetText() && + linkXml && linkXml->GetText()) { + std::string link = linkXml->GetText(); + std::string title = titleXml->GetText(); + std::string desc = parse_html(descXml->GetText()); + // Limit the description text to 4 lines + std::string::size_type i = 0; + int j = 0; + while (true) { + i = desc.find('\n', i); + if (i == std::string::npos) + break; + i++; + j++; + if (j == 5) + desc = desc.substr(0, i); + } - std::string link = linkXml->GetText(); - std::string title = titleXml->GetText(); - std::string desc = parse_html(descXml->GetText()); - - // Limit the description text to 4 lines - std::string::size_type i = 0; - int j = 0; - while (true) { - i = desc.find('\n', i); - if (i == std::string::npos) + addChild(new NewsItem(link, title, desc)); + if (++count == 4) break; - i++; - j++; - if (j == 5) - desc = desc.substr(0, i); } - - addChild(new NewsItem(link, title, desc)); - itemXml = itemXml->NextSiblingElement(); - if (++count == 4) - break; } TiXmlElement* linkXml = handle .FirstChild("rss") .FirstChild("channel") .FirstChild("link").ToElement(); - if (linkXml) + if (linkXml && linkXml->GetText()) addChild(new NewsItem(linkXml->GetText(), "More...", "")); if (view)