Title: [206048] trunk/Source/WebCore
Revision
206048
Author
bfulg...@apple.com
Date
2016-09-16 14:20:23 -0700 (Fri, 16 Sep 2016)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206047 => 206048)


--- trunk/Source/WebCore/ChangeLog	2016-09-16 21:17:33 UTC (rev 206047)
+++ trunk/Source/WebCore/ChangeLog	2016-09-16 21:20:23 UTC (rev 206048)
@@ -1,3 +1,30 @@
+2016-09-16  Brent Fulgham  <bfulg...@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  <achristen...@webkit.org>
 
         Use Vector<LChar> instead of StringBuilder for the ASCII parts of URLParser

Modified: trunk/Source/WebCore/page/CaptionUserPreferences.cpp (206047 => 206048)


--- trunk/Source/WebCore/page/CaptionUserPreferences.cpp	2016-09-16 21:17:33 UTC (rev 206047)
+++ trunk/Source/WebCore/page/CaptionUserPreferences.cpp	2016-09-16 21:20:23 UTC (rev 206048)
@@ -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 @@
     : m_pageGroup(group)
     , m_displayMode(ForcedOnly)
     , m_timer(*this, &CaptionUserPreferences::timerFired)
-    , m_testingMode(false)
-    , m_havePreferences(false)
 {
 }
 
@@ -99,9 +97,17 @@
     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 @@
 
 void CaptionUserPreferences::setUserPrefersCaptions(bool preference)
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return;
 
@@ -120,7 +126,7 @@
 
 bool CaptionUserPreferences::userPrefersSubtitles() const
 {
-    Page* page = *(pageGroup().pages().begin());
+    Page* page = currentPage();
     if (!page)
         return false;
 
@@ -129,7 +135,7 @@
 
 void CaptionUserPreferences::setUserPrefersSubtitles(bool preference)
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return;
 
@@ -139,7 +145,7 @@
 
 bool CaptionUserPreferences::userPrefersTextDescriptions() const
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return false;
     
@@ -148,7 +154,7 @@
 
 void CaptionUserPreferences::setUserPrefersTextDescriptions(bool preference)
 {
-    Page* page = *(m_pageGroup.pages().begin());
+    Page* page = currentPage();
     if (!page)
         return;
     

Modified: trunk/Source/WebCore/page/CaptionUserPreferences.h (206047 => 206048)


--- trunk/Source/WebCore/page/CaptionUserPreferences.h	2016-09-16 21:17:33 UTC (rev 206047)
+++ trunk/Source/WebCore/page/CaptionUserPreferences.h	2016-09-16 21:20:23 UTC (rev 206048)
@@ -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 @@
 private:
     void timerFired();
     void notify();
+    Page* currentPage() const;
 
     PageGroup& m_pageGroup;
     mutable CaptionDisplayMode m_displayMode;
@@ -114,11 +114,9 @@
     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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to