vcl/jsdialog/jsdialogbuilder.cxx |   38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

New commits:
commit 668fe5ba93a80f3949d0747917f74292a2606215
Author:     Henry Castro <[email protected]>
AuthorDate: Fri Dec 4 17:00:51 2020 -0400
Commit:     Henry Castro <[email protected]>
CommitDate: Mon Jan 18 21:43:57 2021 +0100

    lok: jsdialog: fix possible nullptr dereference
    
    p = nullptr;
    
    if (p)
    {
    }
    
    p->Somenthing();
    
    Change-Id: I2a46d6a8e7eae96928210c8941ec71eed88bf631
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107245
    Tested-by: Jenkins
    Reviewed-by: Henry Castro <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109136
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 649893bb6832..49cbac450087 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -375,35 +375,37 @@ VclPtr<vcl::Window>& 
JSInstanceBuilder::GetNotifierWindow()
 
 std::unique_ptr<weld::Dialog> JSInstanceBuilder::weld_dialog(const OString& 
id, bool bTakeOwnership)
 {
+    std::unique_ptr<weld::Dialog> pRet;
     ::Dialog* pDialog = m_xBuilder->get<::Dialog>(id);
-    m_nWindowId = pDialog->GetLOKWindowId();
-    pDialog->SetLOKTunnelingState(false);
-
-    InsertWindowToMap(m_nWindowId);
 
     if (bTakeOwnership && pDialog)
     {
+        m_nWindowId = pDialog->GetLOKWindowId();
+        pDialog->SetLOKTunnelingState(false);
+
+        InsertWindowToMap(m_nWindowId);
+
         assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed");
         m_aOwnedToplevel.set(pDialog);
         m_xBuilder->drop_ownership(pDialog);
         m_bHasTopLevelDialog = true;
-    }
 
-    std::unique_ptr<weld::Dialog> pRet(pDialog ? new 
JSDialog(m_aOwnedToplevel, m_aOwnedToplevel,
-                                                              pDialog, this, 
false, m_sTypeOfJSON)
-                                               : nullptr);
+        pRet.reset(pDialog ? new JSDialog(m_aOwnedToplevel, m_aOwnedToplevel, 
pDialog, this, false,
+                                          m_sTypeOfJSON)
+                           : nullptr);
 
-    RememberWidget("__DIALOG__", pRet.get());
+        RememberWidget("__DIALOG__", pRet.get());
 
-    const vcl::ILibreOfficeKitNotifier* pNotifier = pDialog->GetLOKNotifier();
-    if (pNotifier && id != "MacroSelectorDialog")
-    {
-        std::stringstream aStream;
-        boost::property_tree::ptree aTree = 
m_aOwnedToplevel->DumpAsPropertyTree();
-        aTree.put("id", m_aOwnedToplevel->GetLOKWindowId());
-        boost::property_tree::write_json(aStream, aTree);
-        const std::string message = aStream.str();
-        pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, 
message.c_str());
+        const vcl::ILibreOfficeKitNotifier* pNotifier = 
pDialog->GetLOKNotifier();
+        if (pNotifier && id != "MacroSelectorDialog")
+        {
+            std::stringstream aStream;
+            boost::property_tree::ptree aTree = 
m_aOwnedToplevel->DumpAsPropertyTree();
+            aTree.put("id", m_aOwnedToplevel->GetLOKWindowId());
+            boost::property_tree::write_json(aStream, aTree);
+            const std::string message = aStream.str();
+            pNotifier->libreOfficeKitViewCallback(LOK_CALLBACK_JSDIALOG, 
message.c_str());
+        }
     }
 
     return pRet;
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to