From c75c100218ed5c0e7652947051e28b54a75212ae Mon Sep 17 00:00:00 2001 From: Kevin Hendricks <kevin.b.hendricks@icloud.com> Date: Wed, 26 Jun 2019 14:16:01 -0400 Subject: [PATCH] prevent segfault from malformed opf items --- src/FlightCrew/Framework/ValidateEpub.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/FlightCrew/Framework/ValidateEpub.cpp b/src/FlightCrew/Framework/ValidateEpub.cpp index 9fde065..80235a6 100644 --- a/src/FlightCrew/Framework/ValidateEpub.cpp +++ b/src/FlightCrew/Framework/ValidateEpub.cpp @@ -118,11 +118,16 @@ fs::path GetRelativePathToNcx( const xc::DOMDocument &opf ) std::string href = fromX( item->getAttribute( toX( "href" ) ) ); std::string media_type = fromX( item->getAttribute( toX( "media-type" ) ) ); - if ( xc::XMLUri::isValidURI( true, toX( href ) ) && - media_type == NCX_MIME ) - { - return Util::Utf8PathToBoostPath( Util::UrlDecode( href ) ); - } + // prevent segfault here that would result as toX() will return null when + // passed and empty string + if (!href.empty()) { + + if ( xc::XMLUri::isValidURI( true, toX( href ) ) && + media_type == NCX_MIME ) + { + return Util::Utf8PathToBoostPath( Util::UrlDecode( href ) ); + } + } } return fs::path();