Skip to content

Commit

Permalink
Merge pull request rdkcentral#4914 from melhar098/coverity-p2
Browse files Browse the repository at this point in the history
RDK-45343: [Coverity][SECVULN] Various issues in rdkservices-Phase 2
  • Loading branch information
srikanth-vv authored Mar 14, 2024
2 parents 9ecef91 + 2af3121 commit 422b785
Show file tree
Hide file tree
Showing 30 changed files with 133 additions and 76 deletions.
4 changes: 2 additions & 2 deletions AVInput/AVInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ void AVInput::dsAVVideoModeEventHandler(const char *owner, IARM_EventId_t eventI
if (IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE == eventId) {
IARM_Bus_DSMgr_EventData_t *eventData = (IARM_Bus_DSMgr_EventData_t *)data;
int hdmi_in_port = eventData->data.hdmi_in_video_mode.port;
dsVideoPortResolution_t resolution;
dsVideoPortResolution_t resolution = {};
resolution.pixelResolution = eventData->data.hdmi_in_video_mode.resolution.pixelResolution;
resolution.interlaced = eventData->data.hdmi_in_video_mode.resolution.interlaced;
resolution.frameRate = eventData->data.hdmi_in_video_mode.resolution.frameRate;
Expand Down Expand Up @@ -1161,7 +1161,7 @@ std::string AVInput::getSPD(int iPort)
memcpy(&pre,spdVect.data(),sizeof(struct dsSpd_infoframe_st));

char str[200] = {0};
sprintf(str, "Packet Type:%02X,Version:%u,Length:%u,vendor name:%s,product des:%s,source info:%02X",
snprintf(str, sizeof(str), "Packet Type:%02X,Version:%u,Length:%u,vendor name:%s,product des:%s,source info:%02X",
pre.pkttype,pre.version,pre.length,pre.vendor_name,pre.product_des,pre.source_info);
spdbase64 = str;
}
Expand Down
50 changes: 31 additions & 19 deletions Bluetooth/Bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,15 @@ namespace WPEFramework
JsonArray Bluetooth::getPairedDevices()
{
JsonArray deviceArray;
BTRMGR_PairedDevicesList_t pairedDevices;
BTRMGR_PairedDevicesList_t *pairedDevices = (BTRMGR_PairedDevicesList_t*)malloc(sizeof(BTRMGR_PairedDevicesList_t));
if(pairedDevices == nullptr)
{
LOGERR("Failed to allocate memory");
return deviceArray;
}

memset (&pairedDevices, 0, sizeof(pairedDevices));
BTRMGR_Result_t rc = BTRMGR_GetPairedDevices(0, &pairedDevices);
memset (pairedDevices, 0, sizeof(BTRMGR_PairedDevicesList_t));
BTRMGR_Result_t rc = BTRMGR_GetPairedDevices(0, pairedDevices);
if (BTRMGR_RESULT_SUCCESS != rc)
{
LOGERR("Failed to get the paired devices");
Expand All @@ -426,26 +431,32 @@ namespace WPEFramework
{
int i = 0;
JsonObject deviceDetails;
LOGINFO ("Success.... Paired %d Devices", pairedDevices.m_numOfDevices);
for (; i < pairedDevices.m_numOfDevices; i++)
LOGINFO ("Success.... Paired %d Devices", pairedDevices->m_numOfDevices);
for (; i < pairedDevices->m_numOfDevices; i++)
{
deviceDetails["deviceID"] = std::to_string(pairedDevices.m_deviceProperty[i].m_deviceHandle);
deviceDetails["name"] = string(pairedDevices.m_deviceProperty[i].m_name);
deviceDetails["deviceType"] = string(BTRMGR_GetDeviceTypeAsString(pairedDevices.m_deviceProperty[i].m_deviceType));
deviceDetails["connected"] = pairedDevices.m_deviceProperty[i].m_isConnected?true:false;
deviceDetails["deviceID"] = std::to_string(pairedDevices->m_deviceProperty[i].m_deviceHandle);
deviceDetails["name"] = string(pairedDevices->m_deviceProperty[i].m_name);
deviceDetails["deviceType"] = string(BTRMGR_GetDeviceTypeAsString(pairedDevices->m_deviceProperty[i].m_deviceType));
deviceDetails["connected"] = pairedDevices->m_deviceProperty[i].m_isConnected?true:false;
deviceArray.Add(deviceDetails);
}
}
free(pairedDevices);
return deviceArray;
}

JsonArray Bluetooth::getConnectedDevices()
{
JsonArray deviceArray;
BTRMGR_ConnectedDevicesList_t connectedDevices;
BTRMGR_ConnectedDevicesList_t *connectedDevices = (BTRMGR_ConnectedDevicesList_t*)malloc(sizeof(BTRMGR_ConnectedDevicesList_t));
if(connectedDevices == nullptr)
{
LOGERR("Failed to allocate memory");
return deviceArray;
}

memset (&connectedDevices, 0, sizeof(connectedDevices));
BTRMGR_Result_t rc = BTRMGR_GetConnectedDevices(0, &connectedDevices);
memset (connectedDevices, 0, sizeof(BTRMGR_ConnectedDevicesList_t));
BTRMGR_Result_t rc = BTRMGR_GetConnectedDevices(0, connectedDevices);
if (BTRMGR_RESULT_SUCCESS != rc)
{
LOGERR("Failed to get the connected devices");
Expand All @@ -454,16 +465,17 @@ namespace WPEFramework
{
int i = 0;
JsonObject deviceDetails;
LOGINFO ("Success.... Connected %d Devices", connectedDevices.m_numOfDevices);
for (; i < connectedDevices.m_numOfDevices; i++)
LOGINFO ("Success.... Connected %d Devices", connectedDevices->m_numOfDevices);
for (; i < connectedDevices->m_numOfDevices; i++)
{
deviceDetails["deviceID"] = std::to_string(connectedDevices.m_deviceProperty[i].m_deviceHandle);
deviceDetails["name"] = string(connectedDevices.m_deviceProperty[i].m_name);
deviceDetails["deviceType"] = string(BTRMGR_GetDeviceTypeAsString(connectedDevices.m_deviceProperty[i].m_deviceType));
deviceDetails["activeState"] = std::to_string(connectedDevices.m_deviceProperty[i].m_powerStatus);
deviceDetails["deviceID"] = std::to_string(connectedDevices->m_deviceProperty[i].m_deviceHandle);
deviceDetails["name"] = string(connectedDevices->m_deviceProperty[i].m_name);
deviceDetails["deviceType"] = string(BTRMGR_GetDeviceTypeAsString(connectedDevices->m_deviceProperty[i].m_deviceType));
deviceDetails["activeState"] = std::to_string(connectedDevices->m_deviceProperty[i].m_powerStatus);
deviceArray.Add(deviceDetails);
}
}
free(connectedDevices);
return deviceArray;
}

Expand Down Expand Up @@ -862,7 +874,7 @@ namespace WPEFramework
return mediaTrackInfo;
}

void Bluetooth::notifyEventWrapper (BTRMGR_EventMessage_t eventMsg)
void Bluetooth::notifyEventWrapper (BTRMGR_EventMessage_t &eventMsg)
{
JsonObject params;
string profileInfo;
Expand Down
2 changes: 1 addition & 1 deletion Bluetooth/Bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace WPEFramework {

public:
static Bluetooth* _instance;
void notifyEventWrapper (BTRMGR_EventMessage_t eventMsg);
void notifyEventWrapper (BTRMGR_EventMessage_t &eventMsg);

private:
static const string STATUS_NO_BLUETOOTH_HARDWARE;
Expand Down
17 changes: 13 additions & 4 deletions ContinueWatching/ContinueWatching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,9 @@ namespace WPEFramework {
}

fseek(file, 0, SEEK_SET);
fread(jsonDoc, numbytes, 1, file);
if(numbytes >= 0) {
(void)fread(jsonDoc, numbytes, 1, file);
}
fclose(file);
file = NULL;
jsonDoc[numbytes] = 0;
Expand Down Expand Up @@ -646,7 +648,9 @@ namespace WPEFramework {
}

fseek(file, 0, SEEK_SET);
fread(jsonDoc, 1, numbytes, file);
if(numbytes >= 0) {
(void)fread(jsonDoc, numbytes, 1, file);
}
fclose(file);
jsonDoc[numbytes] = '\0';

Expand Down Expand Up @@ -705,7 +709,9 @@ namespace WPEFramework {
return false;
}
fseek(file, 0, SEEK_SET);
fread(jsonDoc, numbytes, 1, file);
if(numbytes >= 0) {
(void)fread(jsonDoc, numbytes, 1, file);
}
fclose(file);
file = NULL;
jsonDoc[numbytes] = 0;
Expand Down Expand Up @@ -764,7 +770,10 @@ namespace WPEFramework {
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256Ctx;
SHA256_Init(&sha256Ctx);
SHA256_Update(&sha256Ctx, str.c_str(), str.size());
int check_update = SHA256_Update(&sha256Ctx, str.c_str(), str.size());
if(check_update == 0){
LOGWARN("Failed hash update");
}
SHA256_Final(hash, &sha256Ctx);
std::stringstream strStream;
/* Iterate through hash & convert each byte to 2-char wide hex */
Expand Down
2 changes: 1 addition & 1 deletion ContinueWatching/ContinueWatching.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace WPEFramework {

std::string mStrApplicationName;
#if !defined(DISABLE_SECAPI)
SEC_OBJECTID mSecObjectId;
SEC_OBJECTID mSecObjectId = 0;
#endif
};

Expand Down
27 changes: 14 additions & 13 deletions ControlService/ControlService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ namespace WPEFramework {
ControlService::ControlService()
: PluginHost::JSONRPC()
, m_apiVersionNumber((uint32_t)-1) /* default max uint32_t so everything gets enabled */ //TODO(MROLLINS) Can't we access this from jsonrpc interface?
, m_numOfBindRemotes(0)
{
LOGINFO("ctor");
ControlService::_instance = this;
Expand Down Expand Up @@ -228,11 +229,11 @@ namespace WPEFramework {
}
}

void ControlService::irmgrHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
void ControlService::irmgrHandler(const char *owner, IARM_EventId_t eventId, void *dataP, size_t len)
{
if (eventId == IARM_BUS_IRMGR_EVENT_IRKEY)
{
IARM_Bus_IRMgr_EventData_t *irEventData = (IARM_Bus_IRMgr_EventData_t*)data;
IARM_Bus_IRMgr_EventData_t *irEventData = (IARM_Bus_IRMgr_EventData_t*)dataP;
int keyCode = irEventData->data.irkey.keyCode;
int keySrc = irEventData->data.irkey.keySrc;
int keyType = irEventData->data.irkey.keyType;
Expand Down Expand Up @@ -269,14 +270,14 @@ namespace WPEFramework {
}
}

void ControlService::ctrlmHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len)
void ControlService::ctrlmHandler(const char *owner, IARM_EventId_t eventId, void *dataP, size_t len)
{
if (eventId == CTRLM_RCU_IARM_EVENT_KEY_GHOST)
{
LOGINFO("Got a controlMgr ghost key event!");
if (data != NULL)
if (dataP != NULL)
{
ctrlm_rcu_iarm_event_key_ghost_t *msg = (ctrlm_rcu_iarm_event_key_ghost_t*)data;
ctrlm_rcu_iarm_event_key_ghost_t *msg = (ctrlm_rcu_iarm_event_key_ghost_t*)dataP;
int remoteId = msg->controller_id;
int ghostCode = msg->ghost_code;

Expand Down Expand Up @@ -332,9 +333,9 @@ namespace WPEFramework {
len, sizeof(ctrlm_rcu_iarm_event_battery_t));
return;
}
if (data != NULL)
if (dataP != NULL)
{
ctrlm_rcu_iarm_event_battery_t *msg = (ctrlm_rcu_iarm_event_battery_t*)data;
ctrlm_rcu_iarm_event_battery_t *msg = (ctrlm_rcu_iarm_event_battery_t*)dataP;
if (msg->api_revision == CTRLM_RCU_IARM_BUS_API_REVISION)
{
int remoteId = msg->controller_id;
Expand Down Expand Up @@ -370,9 +371,9 @@ namespace WPEFramework {
len, sizeof(ctrlm_rcu_iarm_event_remote_reboot_t));
return;
}
if (data != NULL)
if (dataP != NULL)
{
ctrlm_rcu_iarm_event_remote_reboot_t *msg = (ctrlm_rcu_iarm_event_remote_reboot_t*)data;
ctrlm_rcu_iarm_event_remote_reboot_t *msg = (ctrlm_rcu_iarm_event_remote_reboot_t*)dataP;
if (msg->api_revision == CTRLM_RCU_IARM_BUS_API_REVISION)
{
int remoteId = msg->controller_id;
Expand Down Expand Up @@ -413,9 +414,9 @@ namespace WPEFramework {
len, sizeof(ctrlm_rcu_iarm_event_reverse_cmd_t));
return;
}
if (data != NULL)
if (dataP != NULL)
{
ctrlm_rcu_iarm_event_reverse_cmd_t *msg = (ctrlm_rcu_iarm_event_reverse_cmd_t*)data;
ctrlm_rcu_iarm_event_reverse_cmd_t *msg = (ctrlm_rcu_iarm_event_reverse_cmd_t*)dataP;
if (msg->api_revision == CTRLM_RCU_IARM_BUS_API_REVISION)
{
ctrlm_rcu_reverse_cmd_t cmd = msg->action;
Expand Down Expand Up @@ -463,9 +464,9 @@ namespace WPEFramework {
else if (eventId == CTRLM_RCU_IARM_EVENT_CONTROL)
{
LOGINFO("Got a controlMgr control event!");
if (data != NULL)
if (dataP != NULL)
{
ctrlm_rcu_iarm_event_control_t *msg = (ctrlm_rcu_iarm_event_control_t*)data;
ctrlm_rcu_iarm_event_control_t *msg = (ctrlm_rcu_iarm_event_control_t*)dataP;
int remoteId = msg->controller_id;
int value = msg->event_value;
int spare_value = msg->spare_value;
Expand Down
1 change: 0 additions & 1 deletion ControlService/test/controlSvcTestClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,6 @@ int main(int argc, char** argv)
cmd = lastCmd;
else if ((cmd[0] >= '0') && (cmd[0] <= '9'))
{
choice = stoi(cmd);
remoteId = 255;
timeOutPeriod = 0;
pairingMode = 255;
Expand Down
14 changes: 10 additions & 4 deletions DataCapture/DataCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace WPEFramework {
Register(METHOD_ENABLE_AUDIO_CAPTURE, &DataCapture::enableAudioCaptureWrapper, this);
Register(METHOD_GET_AUDIO_CLIP, &DataCapture::getAudioClipWrapper, this);

_audio_properties = {};
_sock_adaptor.reset(new socket_adaptor());
}

Expand Down Expand Up @@ -513,10 +514,15 @@ namespace WPEFramework {
chunk = curl_slist_append(chunk, "Content-Type: audio/x-wav");

//set url and data
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.size());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, &data[0]);
if(curl_easy_setopt(curl, CURLOPT_URL, url) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_URL");
if(curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_HTTPHEADER");
if(curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, data.size()) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_POSTFIELDSIZE");
if(curl_easy_setopt(curl, CURLOPT_POSTFIELDS, &data[0]) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_POSTFIELDS");


//perform blocking upload call
res = curl_easy_perform(curl);
Expand Down
21 changes: 14 additions & 7 deletions DeviceDiagnostics/DeviceDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,20 @@ namespace WPEFramework

if (curl_handle) {

curl_easy_setopt(curl_handle, CURLOPT_URL, "http://127.0.0.1:10999");
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, postData.c_str());
curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, postData.size());
curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); //when redirected, follow the redirections
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeCurlResponse);
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &response);
curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, curlTimeoutInSeconds);
if(curl_easy_setopt(curl_handle, CURLOPT_URL, "http://127.0.0.1:10999") != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_URL");
if(curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, postData.c_str()) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_POSTFIELDS");
if(curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDSIZE, postData.size()) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_POSTFIELDSIZE");
if(curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1) != CURLE_OK) //when redirected, follow the redirections
LOGWARN("Failed to set curl option: CURLOPT_FOLLOWLOCATION");
if(curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeCurlResponse) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_WRITEFUNCTION");
if(curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &response) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_WRITEDATA");
if(curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, curlTimeoutInSeconds) != CURLE_OK)
LOGWARN("Failed to set curl option: CURLOPT_TIMEOUT");

res = curl_easy_perform(curl_handle);
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code);
Expand Down
1 change: 1 addition & 0 deletions DisplayInfo/DisplayInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace Plugin {
public:
explicit Notification(DisplayInfo* parent)
: _parent(*parent)
, _client(nullptr)
{
ASSERT(parent != nullptr);
}
Expand Down
3 changes: 3 additions & 0 deletions DisplaySettings/DisplaySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,7 @@ namespace WPEFramework {
IARM_Bus_PWRMgr_StandbyVideoState_Param_t param;
param.isEnabled = enabled;
strncpy(param.port, portname.c_str(), PWRMGR_MAX_VIDEO_PORT_NAME_LENGTH);
param.port[sizeof(param.port) - 1] = '\0';
if(IARM_RESULT_SUCCESS != IARM_Bus_Call(IARM_BUS_PWRMGR_NAME, IARM_BUS_PWRMGR_API_SetStandbyVideoState, &param, sizeof(param)))
{
LOGERR("Port: %s. enable: %d", param.port, param.isEnabled);
Expand All @@ -2055,6 +2056,7 @@ namespace WPEFramework {
dsMgrStandbyVideoStateParam_t param;
param.isEnabled = enabled;
strncpy(param.port, portname.c_str(), PWRMGR_MAX_VIDEO_PORT_NAME_LENGTH);
param.port[sizeof(param.port) - 1] = '\0';
if(IARM_RESULT_SUCCESS != IARM_Bus_Call(IARM_BUS_DSMGR_NAME, IARM_BUS_DSMGR_API_SetStandbyVideoState, &param, sizeof(param)))
{
LOGERR("Port: %s. enable: %d", param.port, param.isEnabled);
Expand Down Expand Up @@ -4848,6 +4850,7 @@ void DisplaySettings::sendMsgThread()
LOGINFO(" Send request for ARC TERMINATION");
result = DisplaySettings::_instance->setUpHdmiCecSinkArcRouting(false);
}
break;

default:
{
Expand Down
4 changes: 3 additions & 1 deletion FrontPanel/FrontPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ namespace WPEFramework
FrontPanel::FrontPanel()
: PluginHost::JSONRPC()
, m_updateTimer(this)
, m_runUpdateTimer(false)
{
FrontPanel::_instance = this;
m_runUpdateTimer = false;

Register(METHOD_FP_SET_BRIGHTNESS, &FrontPanel::setBrightnessWrapper, this);
Register(METHOD_FP_GET_BRIGHTNESS, &FrontPanel::getBrightnessWrapper, this);
Expand Down Expand Up @@ -244,7 +246,7 @@ namespace WPEFramework
}
}

const void FrontPanel::InitializeIARM()
void FrontPanel::InitializeIARM()
{
if (Utils::IARM::init())
{
Expand Down
2 changes: 1 addition & 1 deletion FrontPanel/FrontPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ namespace WPEFramework {
INTERFACE_ENTRY(PluginHost::IDispatcher)
END_INTERFACE_MAP
private:
const void InitializeIARM();
void InitializeIARM();
void DeinitializeIARM();
static void powerModeChange(const char *owner, IARM_EventId_t eventId, void *data, size_t len);
public:
Expand Down
Loading

0 comments on commit 422b785

Please sign in to comment.