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

Commit 10111c26 authored by Robert Shih's avatar Robert Shih
Browse files

Fix ClearKey session leaks

Destroy sessions in following scenarios:
* when setSecurityLevel fail in openSession_1_1
* before handling mock errors in closeSession
* after releasing offline keySetIds

Bug: 153663446
Test: [Native]MediaDrmClearkeyTest
Test: VtsHalDrmV1_<0|1|2|3>TargetTest
Change-Id: I4357051e0be6daa199c5fc3e7505ce65d982e237
parent 02ec2d9d
Loading
Loading
Loading
Loading
+8 −2
Original line number Original line Diff line number Diff line
@@ -139,8 +139,13 @@ Return<void> DrmPlugin::openSession_1_1(SecurityLevel securityLevel,
    std::vector<uint8_t> sessionId = session->sessionId();
    std::vector<uint8_t> sessionId = session->sessionId();


    Status status = setSecurityLevel(sessionId, securityLevel);
    Status status = setSecurityLevel(sessionId, securityLevel);
    _hidl_cb(status, toHidlVec(sessionId));
    if (status == Status::OK) {
        mOpenSessionOkCount++;
        mOpenSessionOkCount++;
    } else {
        mSessionLibrary->destroySession(session);
        sessionId.clear();
    }
    _hidl_cb(status, toHidlVec(sessionId));
    return Void();
    return Void();
}
}


@@ -151,12 +156,12 @@ Return<Status> DrmPlugin::closeSession(const hidl_vec<uint8_t>& sessionId) {


    sp<Session> session = mSessionLibrary->findSession(toVector(sessionId));
    sp<Session> session = mSessionLibrary->findSession(toVector(sessionId));
    if (session.get()) {
    if (session.get()) {
        mSessionLibrary->destroySession(session);
        if (session->getMockError() != Status_V1_2::OK) {
        if (session->getMockError() != Status_V1_2::OK) {
            sendSessionLostState(sessionId);
            sendSessionLostState(sessionId);
            return Status::ERROR_DRM_INVALID_STATE;
            return Status::ERROR_DRM_INVALID_STATE;
        }
        }
        mCloseSessionOkCount++;
        mCloseSessionOkCount++;
        mSessionLibrary->destroySession(session);
        return Status::OK;
        return Status::OK;
    }
    }
    mCloseSessionNotOpenedCount++;
    mCloseSessionNotOpenedCount++;
@@ -387,6 +392,7 @@ Return<void> DrmPlugin::provideKeyResponse(
        if (isOfflineLicense) {
        if (isOfflineLicense) {
            if (isRelease) {
            if (isRelease) {
                mFileHandle.DeleteLicense(keySetId);
                mFileHandle.DeleteLicense(keySetId);
                mSessionLibrary->destroySession(session);
            } else {
            } else {
                if (!makeKeySetId(&keySetId)) {
                if (!makeKeySetId(&keySetId)) {
                    _hidl_cb(Status::ERROR_DRM_UNKNOWN, hidl_vec<uint8_t>());
                    _hidl_cb(Status::ERROR_DRM_UNKNOWN, hidl_vec<uint8_t>());