diff --git a/source/app/libpd.c b/source/app/libpd.c index 0f053435..3006e620 100644 --- a/source/app/libpd.c +++ b/source/app/libpd.c @@ -133,6 +133,9 @@ static void connect_parodus() WalPrint("libparodus_shutdown retval %d\n", retval); } } + /* CID-71358 CID-55326 Resource leak fix */ + WAL_FREE(parodus_url); + WAL_FREE(client_url); } //set global conn status and to awake waiting getter threads @@ -194,6 +197,8 @@ static void parodus_receive() memset(res_headers, 0, (sizeof(headers_t) + sizeof( char * ) * (wrp_msg->u.req.headers->count))); } else { + /* CID-59824 Resource leak fix */ + WAL_FREE(res_wrp_msg); WalError("Memory not allocated for response headers\n"); return; } @@ -213,6 +218,12 @@ static void parodus_receive() WalInfo("res header %d in res_wrp_msg - %s\n", i, res_wrp_msg->u.req.headers->headers[i]); } } + else + { + /* CID-334851 Resource leak fix */ + WalInfo("Deallocating memory for non processing response headers\n"); + WAL_FREE(res_headers); + } } else if(res_headers != NULL) { @@ -257,7 +268,7 @@ static void parodus_receive() } getCurrentTime(endPtr); WalInfo("Elapsed time : %ld ms\n", timeValDiff(startPtr, endPtr)); - wrp_free_struct (res_wrp_msg); + wrp_free_struct (res_wrp_msg); } wrp_free_struct (wrp_msg); } @@ -280,6 +291,10 @@ static void parodus_receive() WalPrint("set cloud-status value as %s\n", status); } } + /* CID-273897 Resource leak fix */ + WAL_FREE(sourceService); + WAL_FREE(sourceApplication); + wrp_free_struct (wrp_msg); } } diff --git a/source/broadband/cosa_webpa_dml.c b/source/broadband/cosa_webpa_dml.c index 2f8fb760..917699ff 100644 --- a/source/broadband/cosa_webpa_dml.c +++ b/source/broadband/cosa_webpa_dml.c @@ -223,7 +223,12 @@ X_RDK_Webpa_SetParamStringValue PCOSA_DML_WEBPA_CONFIG pWebpaCfg = (PCOSA_DML_WEBPA_CONFIG)pWebpa->pWebpaCfg; WalPrint("<========= Start of X_RDK_Webpa_SetParamStringValue ========>\n"); - WalInfo("Received data ParamName %s,data length: %d bytes\n",ParamName, strlen(pString)); + /* CID-255476 Dereference before null check fix */ + if (pString != NULL) { + WalInfo("Received data ParamName %s,data length: %d bytes\n",ParamName, strlen(pString)); + } else { + WalInfo("Received data ParamName %s, pString is NULL\n",ParamName); + } if( AnscEqualString(ParamName, "ConnectedClientNotify", TRUE)) { diff --git a/source/broadband/ssp_main.c b/source/broadband/ssp_main.c index 48b76bed..3108cd4d 100755 --- a/source/broadband/ssp_main.c +++ b/source/broadband/ssp_main.c @@ -134,25 +134,6 @@ if ( bRunAsDaemon ) { return WDMP_FAILURE; } - else - { - while ( cmdChar != 'q' ) - { - cmdChar = getchar(); - - cmd_dispatch(cmdChar); - } - } - - err = Cdm_Term(); - if (err != CCSP_SUCCESS) - { - fprintf(stderr, "Cdm_Term: %s\n", Cdm_StrError(err)); - exit(1); - } - - ssp_cancel(); - return WDMP_SUCCESS; } /*----------------------------------------------------------------------------*/ diff --git a/source/broadband/ssp_messagebus_interface.c b/source/broadband/ssp_messagebus_interface.c index 4f4aed81..e7e61556 100755 --- a/source/broadband/ssp_messagebus_interface.c +++ b/source/broadband/ssp_messagebus_interface.c @@ -22,6 +22,8 @@ ANSC_STATUS ssp_Mbi_MessageBusEngage(char * component_id,char * config_file,char if ( ! component_id || ! path ) { CcspTraceError((" !!! ssp_Mbi_MessageBusEngage: component_id or path is NULL !!!\n")); + /* CID-53104 Return failure if component_id or path is NULL */ + return ANSC_STATUS_FAILURE; } /* Connect to message bus */ @@ -42,7 +44,8 @@ ANSC_STATUS ssp_Mbi_MessageBusEngage(char * component_id,char * config_file,char return returnStatus; } - CcspTraceInfo(("INFO: bus_handle: 0x%8x \n", bus_handle)); + /* CID 268716 Invalid printf format specifier fix*/ + CcspTraceInfo(("INFO: bus_handle: %p \n", bus_handle)); g_MessageBusHandle_Irep = bus_handle; AnscCopyString(g_SubSysPrefix_Irep, g_Subsystem); diff --git a/source/broadband/webpa_internal.c b/source/broadband/webpa_internal.c index 40410d1d..9df8875f 100644 --- a/source/broadband/webpa_internal.c +++ b/source/broadband/webpa_internal.c @@ -1099,6 +1099,7 @@ static void getObjectName(char *str, char *objectName, int objectLevel) static void waitUntilSystemReady() { + int ret = 0; if(checkIfSystemReady()) { WalInfo("Checked CR - System is ready, proceed with component caching\n"); @@ -1107,8 +1108,13 @@ static void waitUntilSystemReady() } else { - CcspBaseIf_Register_Event(bus_handle, NULL, "systemReadySignal"); - + ret = CcspBaseIf_Register_Event(bus_handle, NULL, "systemReadySignal"); + /* CID-65122 Unchecked return value fix */ + if (CCSP_SUCCESS != ret) + { + WalError("Failed to register for systemReadySignal event, ret=%d\n", ret); + return; + } CcspBaseIf_SetCallback2 ( bus_handle, @@ -1474,15 +1480,24 @@ WDMP_STATUS createForceSyncJsonSchema(char *value, char *transactionId, char** s } char *forcesyncVal = strdup(value); - char *forcesynctransID = strdup(transactionId); - cJSON *jsonresponse = NULL; + /*CID-565213 CID-565214 Resource leak fix*/ + if(forcesyncVal == NULL) + { + WalError("Memory allocation failed in createForceSyncJsonSchema for forcesyncVal\n"); + return WDMP_FAILURE; + } - if (forcesyncVal == NULL || forcesynctransID == NULL) + char *forcesynctransID = strdup(transactionId); + /*CID-565213 CID-565214 Resource leak fix*/ + if(forcesynctransID == NULL) { - WalError("Memory allocation failed in createForceSyncJsonSchema\n"); + WalError("Memory allocation failed in createForceSyncJsonSchema for forcesynctransID\n"); + WAL_FREE(forcesyncVal); return WDMP_FAILURE; } + cJSON *jsonresponse = NULL; + WalPrint("forcesyncVal %s forcesynctransID %s\n", forcesyncVal, forcesynctransID); jsonresponse = cJSON_CreateObject(); diff --git a/source/broadband/webpa_notification.c b/source/broadband/webpa_notification.c index bc0a4971..3aa794bd 100644 --- a/source/broadband/webpa_notification.c +++ b/source/broadband/webpa_notification.c @@ -273,7 +273,6 @@ void initNotifyTask(int status) { int err = 0; pthread_t threadId; - notifyMsgQ = NULL; int *device_status = (int *) malloc(sizeof(int)); *device_status = status; @@ -506,6 +505,9 @@ void ccspWebPaValueChangedCB(parameterSigStruct_t* val, int size, void* user_dat WalInfo("set g_syncNotifyInProgress, g_checkSyncNotifyRetry to 1\n"); paramNotify= (ParamNotify *) malloc(sizeof(ParamNotify)); + /* CID-565403 Uninitialized pointer read Fix */ + memset(paramNotify, 0, sizeof(ParamNotify)); + if(val->parameterName != NULL) paramNotify->paramName = strdup(val->parameterName); if(val->oldValue != NULL) @@ -519,7 +521,8 @@ void ccspWebPaValueChangedCB(parameterSigStruct_t* val, int size, void* user_dat notifyDataPtr->type = PARAM_NOTIFY; notifyDataPtr->u.notify = paramNotify; - WalInfo("Notification Event from stack: Parameter Name: %s, Data Type: %d, Change Source: %d\n", paramNotify->paramName, paramNotify->type, paramNotify->changeSource); + /* CID-565403 Uninitialized pointer read Fix */ + WalInfo("Notification Event from stack: Parameter Name: %s, Data Type: %d, Change Source: %d\n", paramNotify->paramName ? paramNotify->paramName : "NULL", paramNotify->type, paramNotify->changeSource); (*notifyCbFn)(notifyDataPtr); } @@ -1566,12 +1569,24 @@ void processNotification(NotifyData *notifyData) if(read_sync_notify_from_file() == 1) { WalError("Error while reading param_notify_retry_string from file\n"); + /* CID-57566 Resource leak fix */ + WAL_FREE(cid); + /* CID-565401 Resource Leak Fix */ + WAL_FREE(dest); + cJSON_Delete(notifyPayload); + freeNotifyMessage(notifyData); return; } } cJSON *parameter = cJSON_Parse(param_notify_string); if (parameter == NULL) { WalError("Error in parsing JSON file '%s' content\n",SYNC_NOTIFY_PARAM_BACKUP_FILE); + /* CID-57566 Resource leak fix */ + WAL_FREE(cid); + /* CID-565401 Resource Leak Fix */ + WAL_FREE(dest); + cJSON_Delete(notifyPayload); + freeNotifyMessage(notifyData); return; } cJSON_AddItemToObject(notifyPayload, "parameter", parameter); diff --git a/source/broadband/webpa_rbus.c b/source/broadband/webpa_rbus.c index 4219a57b..fe0f1e70 100644 --- a/source/broadband/webpa_rbus.c +++ b/source/broadband/webpa_rbus.c @@ -51,7 +51,8 @@ void webpaRbus_Uninit() rbusError_t setTraceContext(char* traceContext[]) { rbusError_t ret = RBUS_ERROR_BUS_ERROR; - if(isRbusInitialized) + /* CID-334852 Function address comparison fix */ + if(isRbusInitialized()) { if(traceContext[0] != NULL && traceContext[1] != NULL) { if(strlen(traceContext[0]) > 0 && strlen(traceContext[1]) > 0) { @@ -83,7 +84,8 @@ rbusError_t getTraceContext(char* traceContext[]) rbusError_t ret = RBUS_ERROR_BUS_ERROR; char traceParent[512] = {'\0'}; char traceState[512] = {'\0'}; - if(isRbusInitialized) + /* CID-334847 Function address comparison fix */ + if(isRbusInitialized()) { ret = rbusHandle_GetTraceContextAsString(rbus_handle, traceParent, sizeof(traceParent), traceState, sizeof(traceState)); if( ret == RBUS_ERROR_SUCCESS) { @@ -110,7 +112,8 @@ rbusError_t getTraceContext(char* traceContext[]) rbusError_t clearTraceContext() { rbusError_t ret = RBUS_ERROR_BUS_ERROR; - if(isRbusInitialized) + /* CID-334849 Function address comparison fix */ + if(isRbusInitialized()) { ret = rbusHandle_ClearTraceContext(rbus_handle); if(ret == RBUS_ERROR_SUCCESS) { @@ -123,4 +126,6 @@ rbusError_t clearTraceContext() else { WalError("Rbus not initialized in clearTraceContext funcion\n"); } + /* CID-334846 missing return statement fix */ + return ret; } diff --git a/source/broadband/webpa_replace.c b/source/broadband/webpa_replace.c index 72b5dbcc..318d2799 100644 --- a/source/broadband/webpa_replace.c +++ b/source/broadband/webpa_replace.c @@ -98,17 +98,6 @@ void replaceTable(char *objectName,TableData * list,unsigned int paramcount,WDMP WalError("Failed to replace table, hence reverting the changes\n"); addCachedData(objectName,addList,rowCount); } - for ( cnt = 0 ; cnt < rowCount ; cnt++) - { - for(cnt1 = 0; cnt1 < numParams; cnt1++) - { - WAL_FREE(addList[cnt].names[cnt1]); - WAL_FREE(addList[cnt].values[cnt1]); - } - WAL_FREE(addList[cnt].names); - WAL_FREE(addList[cnt].values); - } - WAL_FREE(addList); } } else @@ -130,6 +119,21 @@ void replaceTable(char *objectName,TableData * list,unsigned int paramcount,WDMP WalError("deleteList is NULL\n"); } } + /* CID-280996 Resource leak fix */ + if(addList != NULL) + { + for ( cnt = 0 ; cnt < rowCount ; cnt++) + { + for(cnt1 = 0; cnt1 < addList[cnt].paramCnt; cnt1++) + { + WAL_FREE(addList[cnt].names[cnt1]); + WAL_FREE(addList[cnt].values[cnt1]); + } + WAL_FREE(addList[cnt].names); + WAL_FREE(addList[cnt].values); + } + WAL_FREE(addList); + } } if(isWalStatus == 1) { @@ -301,7 +305,8 @@ static int addNewData(char *objectName,TableData * list,int paramcount) OnboardLog("Failed to add/update row to %s table, addRet : %d, hence deleting the already added rows\n", objectName, addRet); for(i= cnt-1; i >= 0; i--) { - strncpy(paramName,retObject[i],sizeof(paramName)); + /* CID-182375 Buffer not null terminated fix */ + walStrncpy(paramName,retObject[i],sizeof(paramName)); deleteRowTable(paramName, &delRet); WalPrint("delRet : %d\n",delRet); if(delRet != WDMP_SUCCESS) @@ -506,6 +511,8 @@ static int getWritableParams(char *paramName, char ***writableParams, int *param { WalInfo("Rbus = %s\n", isRbus); rbusMode = (strncmp(isRbus, "true", strlen("true")) == 0) ? 1 : 0; + /* CID-320315 Memory leak fix */ + WAL_FREE(isRbus); } else {