CaptionUserPreferences's use of the PageGroup's page map is incorrect
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Sep 2016 21:20:23 +0000 (21:20 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Sep 2016 21:20:23 +0000 (21:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122194
<rdar://problem/27332004>

Reviewed by Zalan Bujtas.

Avoid the possibility of dereferencing an unsafe iterator by checking
for an empty HashSet before using the result of 'begin()'.

No new tests because there is no change in behavior.

* page/CaptionUserPreferences.cpp:
(WebCore::CaptionUserPreferences::CaptionUserPreferences): Use new safer
accessor to retrieve the current page.
(WebCore::CaptionUserPreferences::setCaptionDisplayMode): Ditto.
(WebCore::CaptionUserPreferences::currentPage): Added.
(WebCore::CaptionUserPreferences::userPrefersCaptions): Use new safer
accessor to retrieve the current page.
(WebCore::CaptionUserPreferences::setUserPrefersCaptions): Ditto.
(WebCore::CaptionUserPreferences::userPrefersSubtitles): Ditto.
(WebCore::CaptionUserPreferences::setUserPrefersSubtitles): Ditto.
(WebCore::CaptionUserPreferences::userPrefersTextDescriptions): Ditto.
(WebCore::CaptionUserPreferences::setUserPrefersTextDescriptions): Ditto.
* page/CaptionUserPreferences.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206048 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/page/CaptionUserPreferences.cpp
Source/WebCore/page/CaptionUserPreferences.h

index 430365c..ec5286e 100644 (file)
@@ -1,3 +1,30 @@
+2016-09-16  Brent Fulgham  <bfulgham@apple.com>
+
+        CaptionUserPreferences's use of the PageGroup's page map is incorrect
+        https://bugs.webkit.org/show_bug.cgi?id=122194
+        <rdar://problem/27332004>
+
+        Reviewed by Zalan Bujtas.
+
+        Avoid the possibility of dereferencing an unsafe iterator by checking
+        for an empty HashSet before using the result of 'begin()'.
+
+        No new tests because there is no change in behavior.
+
+        * page/CaptionUserPreferences.cpp:
+        (WebCore::CaptionUserPreferences::CaptionUserPreferences): Use new safer
+        accessor to retrieve the current page.
+        (WebCore::CaptionUserPreferences::setCaptionDisplayMode): Ditto.
+        (WebCore::CaptionUserPreferences::currentPage): Added.
+        (WebCore::CaptionUserPreferences::userPrefersCaptions): Use new safer
+        accessor to retrieve the current page.
+        (WebCore::CaptionUserPreferences::setUserPrefersCaptions): Ditto.
+        (WebCore::CaptionUserPreferences::userPrefersSubtitles): Ditto.
+        (WebCore::CaptionUserPreferences::setUserPrefersSubtitles): Ditto.
+        (WebCore::CaptionUserPreferences::userPrefersTextDescriptions): Ditto.
+        (WebCore::CaptionUserPreferences::setUserPrefersTextDescriptions): Ditto.
+        * page/CaptionUserPreferences.h:
+
 2016-09-16  Alex Christensen  <achristensen@webkit.org>
 
         Use Vector<LChar> instead of StringBuilder for the ASCII parts of URLParser
index 80f0bb5..cfea10c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -49,8 +49,6 @@ CaptionUserPreferences::CaptionUserPreferences(PageGroup& group)
     : m_pageGroup(group)
     , m_displayMode(ForcedOnly)
     , m_timer(*this, &CaptionUserPreferences::timerFired)
-    , m_testingMode(false)
-    , m_havePreferences(false)
 {
 }
 
@@ -99,9 +97,17 @@ void CaptionUserPreferences::setCaptionDisplayMode(CaptionUserPreferences::Capti
     notify();
 }
 
+Page* CaptionUserPreferences::currentPage() const
+{
+    if (m_pageGroup.pages().isEmpty())
+        return nullptr;
+
+    return *(m_pageGroup.pages().begin());
+}
+
 bool CaptionUserPreferences::userPrefersCaptions() const
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return false;
 
@@ -110,7 +116,7 @@ bool CaptionUserPreferences::userPrefersCaptions() const
 
 void CaptionUserPreferences::setUserPrefersCaptions(bool preference)
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return;
 
@@ -120,7 +126,7 @@ void CaptionUserPreferences::setUserPrefersCaptions(bool preference)
 
 bool CaptionUserPreferences::userPrefersSubtitles() const
 {
-    Page* page = *(pageGroup().pages().begin());
+    Page* page = currentPage();
     if (!page)
         return false;
 
@@ -129,7 +135,7 @@ bool CaptionUserPreferences::userPrefersSubtitles() const
 
 void CaptionUserPreferences::setUserPrefersSubtitles(bool preference)
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return;
 
@@ -139,7 +145,7 @@ void CaptionUserPreferences::setUserPrefersSubtitles(bool preference)
 
 bool CaptionUserPreferences::userPrefersTextDescriptions() const
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return false;
     
@@ -148,7 +154,7 @@ bool CaptionUserPreferences::userPrefersTextDescriptions() const
 
 void CaptionUserPreferences::setUserPrefersTextDescriptions(bool preference)
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return;
     
index fb52fde..8feea7d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012, 2013  Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2016  Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -23,8 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
-#ifndef CaptionUserPreferences_h
-#define CaptionUserPreferences_h
+#pragma once
 
 #if ENABLE(VIDEO_TRACK)
 
@@ -105,6 +104,7 @@ protected:
 private:
     void timerFired();
     void notify();
+    Page* currentPage() const;
 
     PageGroup& m_pageGroup;
     mutable CaptionDisplayMode m_displayMode;
@@ -114,11 +114,9 @@ private:
     String m_captionsStyleSheetOverride;
     String m_primaryAudioTrackLanguageOverride;
     unsigned m_blockNotificationsCounter { 0 };
-    bool m_testingMode;
-    bool m_havePreferences;
+    bool m_testingMode { false };
+    bool m_havePreferences { false };
 };
     
 }
 #endif
-
-#endif