Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d76b8b58 authored by Jeff Tinker's avatar Jeff Tinker
Browse files

Prevent findSession from creating new sessions

findSession in the SessionLibrary wasn't detecting
the case of a sessionId not found.  Since
DefaultKeyedVector was used, a new session id would
get created instead of returning a null sp.

Test: drm hidl hal vts test

bug:36006836
Change-Id: Iff00d8b84188d2bf9f26bceccf645bb730076378
parent 832fcce0
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -39,9 +39,10 @@ status_t DrmPlugin::closeSession(const Vector<uint8_t>& sessionId) {
    sp<Session> session = mSessionLibrary->findSession(sessionId);
    if (session.get()) {
        mSessionLibrary->destroySession(session);
    }
        return android::OK;
    }
    return android::ERROR_DRM_SESSION_NOT_OPENED;
}

status_t DrmPlugin::getKeyRequest(
        const Vector<uint8_t>& scope,
+5 −2
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ SessionLibrary* SessionLibrary::get() {
    return sSingleton;
}

const sp<Session>& SessionLibrary::createSession() {
sp<Session> SessionLibrary::createSession() {
    Mutex::Autolock lock(mSessionsLock);

    String8 sessionIdString = String8::format("%u", mNextSessionId);
@@ -57,9 +57,12 @@ const sp<Session>& SessionLibrary::createSession() {
    return mSessions.valueFor(sessionId);
}

const sp<Session>& SessionLibrary::findSession(
sp<Session> SessionLibrary::findSession(
        const Vector<uint8_t>& sessionId) {
    Mutex::Autolock lock(mSessionsLock);
    if (mSessions.indexOfKey(sessionId) < 0) {
        return sp<Session>(NULL);
    }
    return mSessions.valueFor(sessionId);
}

+3 −3
Original line number Diff line number Diff line
@@ -31,9 +31,9 @@ class SessionLibrary {
public:
    static SessionLibrary* get();

    const android::sp<Session>& createSession();
    android::sp<Session> createSession();

    const android::sp<Session>& findSession(
    android::sp<Session> findSession(
            const android::Vector<uint8_t>& sessionId);

    void destroySession(const android::sp<Session>& session);
@@ -48,7 +48,7 @@ private:

    android::Mutex mSessionsLock;
    uint32_t mNextSessionId;
    android::DefaultKeyedVector<android::Vector<uint8_t>, android::sp<Session> >
    android::KeyedVector<android::Vector<uint8_t>, android::sp<Session> >
            mSessions;
};