From f88200c6b44a5e68f7d9fabde9ac58c86728acb4 Mon Sep 17 00:00:00 2001
From: Viktor Engelmann <viktor.engelmann@qt.io>
Date: Thu, 6 Apr 2017 15:19:24 +0200
Subject: [PATCH] Add two nullpointer checks

The two nullpointer checks prevent crashes that happened when one
clicked on a link with target="_blank" in 56-based.

Task-number: QTBUG-46713
Change-Id: I1f8a20a52726ab05a85dbca2ec49784985384d06
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
---
 src/core/content_browser_client_qt.cpp | 7 +++++--
 src/core/web_contents_view_qt.cpp      | 6 ++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp
index b30c4dfa7..de6e29de6 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -447,8 +447,11 @@ content::MediaObserver *ContentBrowserClientQt::GetMediaObserver()
 
 void ContentBrowserClientQt::OverrideWebkitPrefs(content::RenderViewHost *rvh, content::WebPreferences *web_prefs)
 {
-    if (content::WebContents *webContents = rvh->GetDelegate()->GetAsWebContents())
-        static_cast<WebContentsDelegateQt*>(webContents->GetDelegate())->overrideWebPreferences(webContents, web_prefs);
+    if (content::WebContents *webContents = rvh->GetDelegate()->GetAsWebContents()) {
+        WebContentsDelegateQt* delegate = static_cast<WebContentsDelegateQt*>(webContents->GetDelegate());
+        if (delegate)
+            delegate->overrideWebPreferences(webContents, web_prefs);
+    }
 }
 
 content::QuotaPermissionContext *ContentBrowserClientQt::CreateQuotaPermissionContext()
diff --git a/src/core/web_contents_view_qt.cpp b/src/core/web_contents_view_qt.cpp
index 4f921bd07..844544887 100644
--- a/src/core/web_contents_view_qt.cpp
+++ b/src/core/web_contents_view_qt.cpp
@@ -118,8 +118,10 @@ gfx::NativeView WebContentsViewQt::GetNativeView() const
 
 void WebContentsViewQt::GetContainerBounds(gfx::Rect* out) const
 {
-    const QRectF r(m_client->viewportRect());
-    *out = gfx::Rect(r.x(), r.y(), r.width(), r.height());
+    if (m_client) {
+        const QRectF r(m_client->viewportRect());
+        *out = gfx::Rect(r.x(), r.y(), r.width(), r.height());
+    }
 }
 
 void WebContentsViewQt::Focus()
-- 
GitLab