2a4ee2
From fd7b2f5fbbee23fc2ab9722fcd605921b7184113 Mon Sep 17 00:00:00 2001
2a4ee2
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
2a4ee2
Date: Thu, 28 Nov 2019 09:50:36 +0000
2a4ee2
Subject: [PATCH] rhbz#1775767 null deref
2a4ee2
2a4ee2
Change-Id: I6941055f9a02b36b5fe621fe89f49f62beb87e67
2a4ee2
---
2a4ee2
 include/sfx2/sidebar/Theme.hxx            |  2 +-
2a4ee2
 sfx2/source/sidebar/SidebarController.cxx |  9 +++--
2a4ee2
 sfx2/source/sidebar/Theme.cxx             | 43 ++++++++++++-----------
2a4ee2
 3 files changed, 29 insertions(+), 25 deletions(-)
2a4ee2
2a4ee2
diff --git a/include/sfx2/sidebar/Theme.hxx b/include/sfx2/sidebar/Theme.hxx
2a4ee2
index 16a4798..b7eaf88 100644
2a4ee2
--- a/include/sfx2/sidebar/Theme.hxx
2a4ee2
+++ b/include/sfx2/sidebar/Theme.hxx
2a4ee2
@@ -175,7 +175,7 @@ public:
2a4ee2
     virtual sal_Bool SAL_CALL hasPropertyByName (const OUString& rsName) override;
2a4ee2
 
2a4ee2
 private:
2a4ee2
-    static Theme& GetCurrentTheme();
2a4ee2
+    static Theme* GetCurrentTheme();
2a4ee2
 
2a4ee2
     std::vector<Image> maImages;
2a4ee2
     std::vector<Color> maColors;
2a4ee2
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
2a4ee2
index 0cad779..764d4e3 100644
2a4ee2
--- a/sfx2/source/sidebar/SidebarController.cxx
2a4ee2
+++ b/sfx2/source/sidebar/SidebarController.cxx
2a4ee2
@@ -258,9 +258,12 @@ void SAL_CALL SidebarController::disposing()
2a4ee2
         mpParentWindow = nullptr;
2a4ee2
     }
2a4ee2
 
2a4ee2
-    Theme::GetPropertySet()->removePropertyChangeListener(
2a4ee2
-        "",
2a4ee2
-        static_cast<css::beans::XPropertyChangeListener*>(this));
2a4ee2
+    Reference<beans::XPropertySet> xPropertySet = Theme::GetPropertySet();
2a4ee2
+    if (xPropertySet)
2a4ee2
+    {
2a4ee2
+        xPropertySet->removePropertyChangeListener("",
2a4ee2
+            static_cast<css::beans::XPropertyChangeListener*>(this));
2a4ee2
+    }
2a4ee2
 
2a4ee2
     maContextChangeUpdate.CancelRequest();
2a4ee2
     maAsynchronousDeckSwitch.CancelRequest();
2a4ee2
diff --git a/sfx2/source/sidebar/Theme.cxx b/sfx2/source/sidebar/Theme.cxx
2a4ee2
index bc6236d..1ef350e 100644
2a4ee2
--- a/sfx2/source/sidebar/Theme.cxx
2a4ee2
+++ b/sfx2/source/sidebar/Theme.cxx
2a4ee2
@@ -34,9 +34,10 @@ using namespace css::uno;
2a4ee2
 
2a4ee2
 namespace sfx2 { namespace sidebar {
2a4ee2
 
2a4ee2
-Theme& Theme::GetCurrentTheme()
2a4ee2
+Theme* Theme::GetCurrentTheme()
2a4ee2
 {
2a4ee2
-    return SfxGetpApp()->GetSidebarTheme();
2a4ee2
+    SfxApplication* pApp = SfxGetpApp();
2a4ee2
+    return pApp ? &pApp->GetSidebarTheme() : nullptr;
2a4ee2
 }
2a4ee2
 
2a4ee2
 Theme::Theme()
2a4ee2
@@ -67,8 +68,8 @@ Image Theme::GetImage (const ThemeItem eItem)
2a4ee2
     const PropertyType eType (GetPropertyType(eItem));
2a4ee2
     OSL_ASSERT(eType==PT_Image);
2a4ee2
     const sal_Int32 nIndex (GetIndex(eItem, eType));
2a4ee2
-    const Theme& rTheme (GetCurrentTheme());
2a4ee2
-    return rTheme.maImages[nIndex];
2a4ee2
+    const Theme* pTheme (GetCurrentTheme());
2a4ee2
+    return pTheme->maImages[nIndex];
2a4ee2
 }
2a4ee2
 
2a4ee2
 Color Theme::GetColor (const ThemeItem eItem)
2a4ee2
@@ -76,11 +77,11 @@ Color Theme::GetColor (const ThemeItem eItem)
2a4ee2
     const PropertyType eType (GetPropertyType(eItem));
2a4ee2
     OSL_ASSERT(eType==PT_Color || eType==PT_Paint);
2a4ee2
     const sal_Int32 nIndex (GetIndex(eItem, eType));
2a4ee2
-    const Theme& rTheme (GetCurrentTheme());
2a4ee2
+    const Theme* pTheme (GetCurrentTheme());
2a4ee2
     if (eType == PT_Color)
2a4ee2
-        return rTheme.maColors[nIndex];
2a4ee2
+        return pTheme->maColors[nIndex];
2a4ee2
     else if (eType == PT_Paint)
2a4ee2
-        return rTheme.maPaints[nIndex].GetColor();
2a4ee2
+        return pTheme->maPaints[nIndex].GetColor();
2a4ee2
     else
2a4ee2
         return COL_WHITE;
2a4ee2
 }
2a4ee2
@@ -90,8 +91,8 @@ const Paint& Theme::GetPaint (const ThemeItem eItem)
2a4ee2
     const PropertyType eType (GetPropertyType(eItem));
2a4ee2
     OSL_ASSERT(eType==PT_Paint);
2a4ee2
     const sal_Int32 nIndex (GetIndex(eItem, eType));
2a4ee2
-    const Theme& rTheme (GetCurrentTheme());
2a4ee2
-    return rTheme.maPaints[nIndex];
2a4ee2
+    const Theme* pTheme (GetCurrentTheme());
2a4ee2
+    return pTheme->maPaints[nIndex];
2a4ee2
 }
2a4ee2
 
2a4ee2
 const Wallpaper Theme::GetWallpaper (const ThemeItem eItem)
2a4ee2
@@ -104,8 +105,8 @@ sal_Int32 Theme::GetInteger (const ThemeItem eItem)
2a4ee2
     const PropertyType eType (GetPropertyType(eItem));
2a4ee2
     OSL_ASSERT(eType==PT_Integer);
2a4ee2
     const sal_Int32 nIndex (GetIndex(eItem, eType));
2a4ee2
-    const Theme& rTheme (GetCurrentTheme());
2a4ee2
-    return rTheme.maIntegers[nIndex];
2a4ee2
+    const Theme* pTheme (GetCurrentTheme());
2a4ee2
+    return pTheme->maIntegers[nIndex];
2a4ee2
 }
2a4ee2
 
2a4ee2
 bool Theme::GetBoolean (const ThemeItem eItem)
2a4ee2
@@ -113,28 +114,28 @@ bool Theme::GetBoolean (const ThemeItem eItem)
2a4ee2
     const PropertyType eType (GetPropertyType(eItem));
2a4ee2
     OSL_ASSERT(eType==PT_Boolean);
2a4ee2
     const sal_Int32 nIndex (GetIndex(eItem, eType));
2a4ee2
-    const Theme& rTheme (GetCurrentTheme());
2a4ee2
-    return rTheme.maBooleans[nIndex];
2a4ee2
+    const Theme* pTheme (GetCurrentTheme());
2a4ee2
+    return pTheme->maBooleans[nIndex];
2a4ee2
 }
2a4ee2
 
2a4ee2
 bool Theme::IsHighContrastMode()
2a4ee2
 {
2a4ee2
-    const Theme& rTheme (GetCurrentTheme());
2a4ee2
-    return rTheme.mbIsHighContrastMode;
2a4ee2
+    const Theme* pTheme (GetCurrentTheme());
2a4ee2
+    return pTheme->mbIsHighContrastMode;
2a4ee2
 }
2a4ee2
 
2a4ee2
 void Theme::HandleDataChange()
2a4ee2
 {
2a4ee2
-    Theme& rTheme (GetCurrentTheme());
2a4ee2
+    Theme* pTheme (GetCurrentTheme());
2a4ee2
 
2a4ee2
-    if ( ! rTheme.mbIsHighContrastModeSetManually)
2a4ee2
+    if (!pTheme->mbIsHighContrastModeSetManually)
2a4ee2
     {
2a4ee2
         // Do not modify mbIsHighContrastMode when it was manually set.
2a4ee2
-        GetCurrentTheme().mbIsHighContrastMode = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
2a4ee2
-        rTheme.maRawValues[Bool_IsHighContrastModeActive] <<= GetCurrentTheme().mbIsHighContrastMode;
2a4ee2
+        GetCurrentTheme()->mbIsHighContrastMode = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
2a4ee2
+        pTheme->maRawValues[Bool_IsHighContrastModeActive] <<= GetCurrentTheme()->mbIsHighContrastMode;
2a4ee2
     }
2a4ee2
 
2a4ee2
-    GetCurrentTheme().UpdateTheme();
2a4ee2
+    GetCurrentTheme()->UpdateTheme();
2a4ee2
 }
2a4ee2
 
2a4ee2
 void Theme::InitializeTheme()
2a4ee2
@@ -369,7 +370,7 @@ void SAL_CALL Theme::disposing()
2a4ee2
 
2a4ee2
 Reference<beans::XPropertySet> Theme::GetPropertySet()
2a4ee2
 {
2a4ee2
-    return Reference<beans::XPropertySet>(static_cast<XWeak*>(&GetCurrentTheme()), UNO_QUERY);
2a4ee2
+    return Reference<beans::XPropertySet>(static_cast<XWeak*>(GetCurrentTheme()), UNO_QUERY);
2a4ee2
 }
2a4ee2
 
2a4ee2
 Reference<beans::XPropertySetInfo> SAL_CALL Theme::getPropertySetInfo()
2a4ee2
-- 
2a4ee2
2.20.1
2a4ee2