From f264146e5926d572e20667f2c3c05eb2fa07a315 Mon Sep 17 00:00:00 2001 From: David Faure Date: Thu, 15 Jan 2015 16:41:22 +0100 Subject: [PATCH] Fix crash when arguments().mimeType() is an invalid mimetype name. I have a JIRA bug report with a PDF attached, and mid-clicking the PDF in konqueror leads to opening an okularpart with mimetype="application/x-octet-stream" (the x- in there is very unusual, and unknown to shared-mime-info). Fixed with null pointer checks. REVIEW: 122074 --- part.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/part.cpp b/part.cpp index 263f3ad0b..36438af1c 100644 --- a/part.cpp +++ b/part.cpp @@ -1325,18 +1325,20 @@ bool Part::openFile() if ( !isstdin && !fileInfo.exists() ) return false; KMimeType::Ptr pathMime = KMimeType::findByPath( fileNameToOpen ); - if ( !arguments().mimeType().isEmpty() ) + const QString argMimeType = arguments().mimeType(); + + if ( !argMimeType.isEmpty() ) { - KMimeType::Ptr argMime = KMimeType::mimeType( arguments().mimeType() ); + KMimeType::Ptr argMime = KMimeType::mimeType( argMimeType ); // Select the "childmost" mimetype, if none of them // inherits the other trust more what pathMime says // but still do a second try if that one fails - if ( argMime->is( pathMime->name() ) ) + if ( argMime && argMime->is( pathMime->name() ) ) { mimes << argMime; } - else if ( pathMime->is( argMime->name() ) ) + else if ( !argMime || pathMime->is( argMime->name() ) ) { mimes << pathMime; }