From 729cf763aef8caec7ac687412b072543ee1acc44 Mon Sep 17 00:00:00 2001 From: trupthi1403 Date: Tue, 26 May 2026 17:24:21 +0530 Subject: [PATCH] RDKEMW-17597-0: Fix Coverity issues Reason for change: Modified to fix CHECKED_RETURN and FORWARD_NULL issues Test procedure: As in ticket Risks: Medium --- drm/ClearKeyDrmSession.cpp | 45 ++++++++++++++----- .../SecManagerThunder.cpp | 7 ++- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/drm/ClearKeyDrmSession.cpp b/drm/ClearKeyDrmSession.cpp index 173c84d9..f52ffe23 100644 --- a/drm/ClearKeyDrmSession.cpp +++ b/drm/ClearKeyDrmSession.cpp @@ -217,21 +217,44 @@ DrmData * ClearKeySession::generateKeyRequest(string& destinationURL, uint32_t t cJSON *keyIds = cJSON_CreateArray(); if(keyIds) { - cJSON_AddItemToArray(keyIds, cJSON_CreateString(urlEncodedkeyId)); - cJSON_AddItemToObject(licenseRequest, "kids", keyIds); - cJSON_AddItemToObject(licenseRequest, "type",cJSON_CreateString("temporary")); - char* requestBody = cJSON_PrintUnformatted(licenseRequest); - if(requestBody) + cJSON *keyIdItem = cJSON_CreateString(urlEncodedkeyId); + + if (!keyIdItem || !cJSON_AddItemToArray(keyIds, keyIdItem)) + { + MW_LOG_ERR("Failed to add keyId to array"); + if(keyIdItem) cJSON_Delete(keyIdItem); + cJSON_Delete(keyIds); + } + else if (!cJSON_AddItemToObject(licenseRequest, "kids", keyIds)) + { + MW_LOG_ERR("Failed to add kids to license request"); + cJSON_Delete(keyIds); + } + else + { + cJSON *typeItem = cJSON_CreateString("temporary"); + + if (!typeItem || !cJSON_AddItemToObject(licenseRequest, "type", typeItem)) { - MW_LOG_INFO("Generated license request : %s", requestBody); - licenseChallenge = new DrmData( requestBody, strlen(requestBody)); //CID:154682 - overrun - m_eKeyState = KEY_PENDING; - cJSON_free(requestBody); + MW_LOG_ERR("Failed to add type to license request"); + if(typeItem) cJSON_Delete(typeItem); + } + else + { + char* requestBody = cJSON_PrintUnformatted(licenseRequest); + if(requestBody) + { + MW_LOG_INFO("Generated license request : %s", requestBody); + licenseChallenge = new DrmData( requestBody, strlen(requestBody)); //CID:154682 - overrun + m_eKeyState = KEY_PENDING; + cJSON_free(requestBody); + } } } - cJSON_Delete(licenseRequest); } - free(urlEncodedkeyId); + cJSON_Delete(licenseRequest); + } + free(urlEncodedkeyId); } } return licenseChallenge; diff --git a/externals/contentsecuritymanager/SecManagerThunder.cpp b/externals/contentsecuritymanager/SecManagerThunder.cpp index ed13d747..2d8252a1 100644 --- a/externals/contentsecuritymanager/SecManagerThunder.cpp +++ b/externals/contentsecuritymanager/SecManagerThunder.cpp @@ -229,10 +229,9 @@ bool SecManagerThunder::AcquireLicenseOpenOrUpdate( std::string clientId, std::s * where input data changes e.g. following a call to updatePlaybackSession * the input data to the shared session is updated here*/ newSession = ContentSecurityManagerSession(response["sessionId"].Number(), - ContentSecurityManager::getInputSummaryHash(moneyTraceMetadata, contentMetadata, - contMetaLen, licenseRequest, keySystemId, - mediaUsage, accessToken, isVideoMuted)); - + ContentSecurityManager::getInputSummaryHash(moneyTraceMetadata, contentMetaDataStr.c_str(), + contMetaLen, licenseRequestStr.c_str(), keySystemId, + mediaUsage, accessTokenStr.c_str(), isVideoMuted)); std::string license = response["license"].String(); MW_LOG_TRACE("SecManager obtained license with length: %d and data: %s",license.size(), license.c_str()); if (!license.empty())