Prechádzať zdrojové kódy

RemoteComponent: fix a crash

Merely opening http://127.0.0.1:32433/player/timeline/poll made PMP
crash. The reason is that in handleCommand(), the handleSubscription()
call above the code modified by this commit does not necessarily add the
client to the m_subscriberMap. As a consequence, the identifier lookup
will make the QMap insert and return a default-constructed item, which
in this case is a 0-pointer. Other code does not expect 0-pointers in
the map, and checkSubscribers() is the thing that will crash next.

Fix this by explicitly checking whether the client as added to the map
at all.

Also, the cast after the lookup should probably be a dynamic cast (it
seems a C-style cast is never dynamic), and that's what the 0-pointer
check is for. This might fix another crash/undefined behavior bug.
Vincent Lang 8 rokov pred
rodič
commit
60db3ea815
1 zmenil súbory, kde vykonal 4 pridanie a 1 odobranie
  1. 4 1
      src/remote/RemoteComponent.cpp

+ 4 - 1
src/remote/RemoteComponent.cpp

@@ -227,7 +227,10 @@ void RemoteComponent::handleCommand(QHttpRequest* request, QHttpResponse* respon
       lk.relock();
     }
 
-    RemotePollSubscriber *subscriber = (RemotePollSubscriber *)m_subscriberMap[identifier];
+    if (!m_subscriberMap.contains(identifier))
+      return;
+
+    RemotePollSubscriber *subscriber = dynamic_cast<RemotePollSubscriber *>(m_subscriberMap[identifier]);
     if (subscriber)
     {
       subscriber->reSubscribe();