From 79f4ad960d2af338b5df84da2b43fb8162028d8e Mon Sep 17 00:00:00 2001 From: Julien Bouix <24aligre@gmail.com> Date: Fri, 5 Jan 2024 20:20:37 +0000 Subject: [PATCH] osr: Fix potential null ptr dereference during DnD --- .../osr/browser_platform_delegate_osr.cc | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/libcef/browser/osr/browser_platform_delegate_osr.cc b/libcef/browser/osr/browser_platform_delegate_osr.cc index d03f85030..1150bee22 100644 --- a/libcef/browser/osr/browser_platform_delegate_osr.cc +++ b/libcef/browser/osr/browser_platform_delegate_osr.cc @@ -333,12 +333,20 @@ void CefBrowserPlatformDelegateOsr::DragTargetDragEnter( const gfx::Point client_pt(event.x, event.y); gfx::PointF transformed_pt; - current_rwh_for_drag_ = - web_contents->GetInputEventRouter() - ->GetRenderWidgetHostAtPoint( - web_contents->GetRenderViewHost()->GetWidget()->GetView(), - gfx::PointF(client_pt), &transformed_pt) - ->GetWeakPtr(); + + // Some random crashes occured when GetWeakPtr is called on a null pointer + // that is the return of GetRenderWidgetHostAtPoint As the root cause is not + // yet understood (no reproducible scenario yet), the current fix is only a + // protection against null pointer dereferencing. + content::RenderWidgetHostImpl* ptr_current_rwh_for_drag = + web_contents->GetInputEventRouter()->GetRenderWidgetHostAtPoint( + web_contents->GetRenderViewHost()->GetWidget()->GetView(), + gfx::PointF(client_pt), &transformed_pt); + if (!ptr_current_rwh_for_drag) { + return; + } + current_rwh_for_drag_ = ptr_current_rwh_for_drag->GetWeakPtr(); + current_rvh_for_drag_ = web_contents->GetRenderViewHost(); drag_data_ = drag_data;