Title: [210349] branches/safari-603-branch/Source/WebCore

Diff

Modified: branches/safari-603-branch/Source/WebCore/ChangeLog (210348 => 210349)


--- branches/safari-603-branch/Source/WebCore/ChangeLog	2017-01-05 17:09:18 UTC (rev 210348)
+++ branches/safari-603-branch/Source/WebCore/ChangeLog	2017-01-05 17:09:20 UTC (rev 210349)
@@ -1,5 +1,35 @@
 2017-01-05  Matthew Hanson  <matthew_han...@apple.com>
 
+        Merge r210104. rdar://problem/29139619
+
+    2016-12-22  Jer Noble  <jer.no...@apple.com>
+
+            NULL-deref CRASH in WebCore::PlatformMediaSession::mediaType
+            https://bugs.webkit.org/show_bug.cgi?id=166407
+
+            Reviewed by Darin Adler.
+
+            In r207688, we added a facility in PlatformMediaSessionManager for safely walking through a
+            list of PlatformMediaSessions by replacing entries of deleted sessions with nullptr. We now
+            need to use those new iteration falicities in MediaSessionManageriOS.
+
+            In addition to the existing iterators, add one which takes a predicate, and returns the first
+            session which matches the predicate, or nullptr, if none do.
+
+            * platform/audio/PlatformMediaSessionManager.cpp:
+            (WebCore::PlatformMediaSessionManager::findSession):
+            (WebCore::PlatformMediaSessionManager::anyOfSessions):
+            * platform/audio/PlatformMediaSessionManager.h:
+            (WebCore::PlatformMediaSessionManager::sessions): Deleted.
+            * platform/audio/ios/MediaSessionManagerIOS.mm:
+            (WebCore::MediaSessionManageriOS::configureWireLessTargetMonitoring):
+            (WebCore::MediaSessionManageriOS::nowPlayingEligibleSession):
+            (WebCore::MediaSessionManageriOS::externalOutputDeviceAvailableDidChange):
+            (WebCore::MediaSessionManageriOS::applicationDidEnterBackground):
+            (WebCore::MediaSessionManageriOS::applicationWillEnterForeground):
+
+2017-01-05  Matthew Hanson  <matthew_han...@apple.com>
+
         Merge r210100. rdar://problem/28388000
 
     2016-12-22  Jer Noble  <jer.no...@apple.com>

Modified: branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp (210348 => 210349)


--- branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2017-01-05 17:09:18 UTC (rev 210348)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.cpp	2017-01-05 17:09:20 UTC (rev 210349)
@@ -401,7 +401,7 @@
     });
 }
 
-void PlatformMediaSessionManager::forEachSession(std::function<void(PlatformMediaSession&, size_t)> func) const
+void PlatformMediaSessionManager::forEachSession(const Function<void(PlatformMediaSession&, size_t)>& predicate) const
 {
     ++m_iteratingOverSessions;
 
@@ -409,7 +409,7 @@
         auto session = m_sessions[i];
         if (!session)
             continue;
-        func(*session, i);
+        predicate(*session, i);
     }
 
     --m_iteratingOverSessions;
@@ -417,20 +417,20 @@
         m_sessions.removeAll(nullptr);
 }
 
-bool PlatformMediaSessionManager::anyOfSessions(std::function<bool(PlatformMediaSession&, size_t)> func) const
+PlatformMediaSession* PlatformMediaSessionManager::findSession(const Function<bool(PlatformMediaSession&, size_t)>& predicate) const
 {
     ++m_iteratingOverSessions;
 
-    bool found = false;
+    PlatformMediaSession* foundSession = nullptr;
     for (size_t i = 0, size = m_sessions.size(); i < size; ++i) {
         auto session = m_sessions[i];
         if (!session)
             continue;
 
-        if (!func(*session, i))
+        if (!predicate(*session, i))
             continue;
 
-        found = true;
+        foundSession = session;
         break;
     }
 
@@ -438,7 +438,7 @@
     if (!m_iteratingOverSessions)
         m_sessions.removeAll(nullptr);
 
-    return found;
+    return foundSession;
 }
 
 #endif // ENABLE(VIDEO) || ENABLE(WEB_AUDIO)

Modified: branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (210348 => 210349)


--- branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2017-01-05 17:09:18 UTC (rev 210348)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2017-01-05 17:09:20 UTC (rev 210349)
@@ -114,14 +114,14 @@
     void addSession(PlatformMediaSession&);
     virtual void removeSession(PlatformMediaSession&);
 
-    Vector<PlatformMediaSession*> sessions() { return m_sessions; }
+    void forEachSession(const Function<void(PlatformMediaSession&, size_t)>&) const;
+    PlatformMediaSession* findSession(const Function<bool(PlatformMediaSession&, size_t)>&) const;
+    bool anyOfSessions(const Function<bool(PlatformMediaSession&, size_t)>& predicate) const { return findSession(predicate); }
 
 private:
     friend class Internals;
 
     void updateSessionState();
-    void forEachSession(std::function<void(PlatformMediaSession&, size_t)>) const;
-    bool anyOfSessions(std::function<bool(PlatformMediaSession&, size_t)>) const;
 
     // RemoteCommandListenerClient
     WEBCORE_EXPORT void didReceiveRemoteControlCommand(PlatformMediaSession::RemoteControlCommandType, const PlatformMediaSession::RemoteCommandArgument*) override;

Modified: branches/safari-603-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (210348 => 210349)


--- branches/safari-603-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm	2017-01-05 17:09:18 UTC (rev 210348)
+++ branches/safari-603-branch/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm	2017-01-05 17:09:20 UTC (rev 210349)
@@ -173,16 +173,10 @@
 
 void MediaSessionManageriOS::configureWireLessTargetMonitoring()
 {
-    Vector<PlatformMediaSession*> sessions = this->sessions();
-    bool requiresMonitoring = false;
+    bool requiresMonitoring = anyOfSessions([] (PlatformMediaSession& session, size_t) {
+        return session.requiresPlaybackTargetRouteMonitoring();
+    });
 
-    for (auto* session : sessions) {
-        if (session->requiresPlaybackTargetRouteMonitoring()) {
-            requiresMonitoring = true;
-            break;
-        }
-    }
-
     LOG(Media, "MediaSessionManageriOS::configureWireLessTargetMonitoring - requiresMonitoring = %s", requiresMonitoring ? "true" : "false");
 
     if (requiresMonitoring)
@@ -223,16 +217,16 @@
 
 PlatformMediaSession* MediaSessionManageriOS::nowPlayingEligibleSession()
 {
-    for (auto session : sessions()) {
-        PlatformMediaSession::MediaType type = session->mediaType();
+    return findSession([] (PlatformMediaSession& session, size_t) {
+        PlatformMediaSession::MediaType type = session.mediaType();
         if (type != PlatformMediaSession::Video && type != PlatformMediaSession::Audio)
-            continue;
+            return false;
 
-        if (session->characteristics() & PlatformMediaSession::HasAudio)
-            return session;
-    }
+        if (session.characteristics() & PlatformMediaSession::HasAudio)
+            return true;
 
-    return nullptr;
+        return false;
+    });
 }
 
 void MediaSessionManageriOS::updateNowPlayingInfo()
@@ -292,10 +286,9 @@
 
 void MediaSessionManageriOS::externalOutputDeviceAvailableDidChange()
 {
-    Vector<PlatformMediaSession*> sessionList = sessions();
-    bool haveTargets = [m_objcObserver hasWirelessTargetsAvailable];
-    for (auto* session : sessionList)
-        session->externalOutputDeviceAvailableDidChange(haveTargets);
+    forEachSession([haveTargets = [m_objcObserver hasWirelessTargetsAvailable]] (PlatformMediaSession& session, size_t) {
+        session.externalOutputDeviceAvailableDidChange(haveTargets);
+    });
 }
 
 void MediaSessionManageriOS::applicationDidEnterBackground(bool isSuspendedUnderLock)
@@ -309,11 +302,10 @@
     if (!isSuspendedUnderLock)
         return;
 
-    Vector<PlatformMediaSession*> sessions = this->sessions();
-    for (auto* session : sessions) {
-        if (restrictions(session->mediaType()) & BackgroundProcessPlaybackRestricted)
-            session->beginInterruption(PlatformMediaSession::SuspendedUnderLock);
-    }
+    forEachSession([this] (PlatformMediaSession& session, size_t) {
+        if (restrictions(session.mediaType()) & BackgroundProcessPlaybackRestricted)
+            session.beginInterruption(PlatformMediaSession::SuspendedUnderLock);
+    });
 }
 
 void MediaSessionManageriOS::applicationWillEnterForeground(bool isSuspendedUnderLock)
@@ -327,11 +319,10 @@
     if (!isSuspendedUnderLock)
         return;
 
-    Vector<PlatformMediaSession*> sessions = this->sessions();
-    for (auto* session : sessions) {
-        if (restrictions(session->mediaType()) & BackgroundProcessPlaybackRestricted)
-            session->endInterruption(PlatformMediaSession::MayResumePlaying);
-    }
+    forEachSession([this] (PlatformMediaSession& session, size_t) {
+        if (restrictions(session.mediaType()) & BackgroundProcessPlaybackRestricted)
+            session.endInterruption(PlatformMediaSession::MayResumePlaying);
+    });
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to