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