diff --git a/source/ccsp/components/CCSP_AliasMgr/ccsp_alias_mgr_base.c b/source/ccsp/components/CCSP_AliasMgr/ccsp_alias_mgr_base.c index fe6c834bf..156cb5a3c 100644 --- a/source/ccsp/components/CCSP_AliasMgr/ccsp_alias_mgr_base.c +++ b/source/ccsp/components/CCSP_AliasMgr/ccsp_alias_mgr_base.c @@ -1070,15 +1070,15 @@ CcspAliasMgrLookupAliasNode pChildNode = pChildNode->Sibling; } } - if ( !pChildNode ) { + /* CID: 154680 - Logically Dead code */ if ( bInsMatched ) { pChildNode = pInsNode; pInsNode = NULL; } - } + } else if ( !StringSListIsEmpty(&pChildNode->Aliases)) { pAliasNode = pChildNode; diff --git a/source/ccsp/components/common/DataModel/dml/components/DslhCpeController/dslh_cpeco_control.c b/source/ccsp/components/common/DataModel/dml/components/DslhCpeController/dslh_cpeco_control.c index e9da97dbe..049876b06 100644 --- a/source/ccsp/components/common/DataModel/dml/components/DslhCpeController/dslh_cpeco_control.c +++ b/source/ccsp/components/common/DataModel/dml/components/DslhCpeController/dslh_cpeco_control.c @@ -1344,8 +1344,17 @@ DslhCpecoRegisterDataModelInternal if ( ( CCSP_SUCCESS != returnStatus ) && ( CCSP_CR_ERR_NAMESPACE_OVERLAP != returnStatus ) ) { AnscTraceWarning(("!!! %s registerCapabilities failed with code %lu! Waiting for %lu seconds to retry...!!! \n", pComponentName, returnStatus, uWait)); - AnscSleep(uWait * 1000); - uWait *=2; + /* Convert to ms safely */ + uint64_t ms = (uint64_t)uWait * 1000ULL; + + /* Clamp for AnscSleep() */ + if (ms > ULONG_MAX) + ms = ULONG_MAX; + + AnscSleep((ULONG)ms); + + /* Exponential backoff: still in seconds! */ + uWait = (uWait <= (ULONG_MAX / 2000)) ? (uWait * 2) : (ULONG_MAX / 1000); } else { diff --git a/source/ccsp/components/common/MessageBusHelper/helper/messagebus_interface_helper.c b/source/ccsp/components/common/MessageBusHelper/helper/messagebus_interface_helper.c index 4615df9d5..c8d515291 100644 --- a/source/ccsp/components/common/MessageBusHelper/helper/messagebus_interface_helper.c +++ b/source/ccsp/components/common/MessageBusHelper/helper/messagebus_interface_helper.c @@ -1185,17 +1185,17 @@ CcspCcMbi_GetParameterNames if( i > 0 ) { - for(--i; (int)i >= 0; --i) + for (ULONG k = i; k-- > 0; ) { - if(ppReturnVal[i]->parameterName) + if(ppReturnVal[k]->parameterName) { - AnscFreeMemory(ppReturnVal[i]->parameterName); - ppReturnVal[i]->parameterName = NULL; + AnscFreeMemory(ppReturnVal[k]->parameterName); + ppReturnVal[k]->parameterName = NULL; } - if(ppReturnVal[i]) + if(ppReturnVal[k]) { - AnscFreeMemory(ppReturnVal[i]); - ppReturnVal[i] = NULL; + AnscFreeMemory(ppReturnVal[k]); + ppReturnVal[k] = NULL; } } } diff --git a/source/cosa/package/cli/components/ScliShell/scli_shell_bic.c b/source/cosa/package/cli/components/ScliShell/scli_shell_bic.c index 18932d4ec..8e32682ea 100644 --- a/source/cosa/package/cli/components/ScliShell/scli_shell_bic.c +++ b/source/cosa/package/cli/components/ScliShell/scli_shell_bic.c @@ -1748,8 +1748,10 @@ ScliShoRunBicAutoCompletion ScliShoInitArgMatchResult(&pOptArgM[i]); } } - - /* trying to auto complete argument name or value */ + if ( !pReqArgM || !pOptArgM ) { + goto EXIT; + } + /* trying to auto complete argument name or value */ bMatched = ScliShoMatchCommand ( @@ -2397,6 +2399,10 @@ ScliShoRunBicHelp } } + if ( !pReqArgM || !pOptArgM ) + { + goto EXIT; + } bMatched = ScliShoMatchCommand ( diff --git a/source/cosa/package/cli/components/ScliShell/scli_shell_exec.c b/source/cosa/package/cli/components/ScliShell/scli_shell_exec.c index 56bb3c7e3..745db188f 100644 --- a/source/cosa/package/cli/components/ScliShell/scli_shell_exec.c +++ b/source/cosa/package/cli/components/ScliShell/scli_shell_exec.c @@ -134,8 +134,7 @@ ScliShoAsyncRunCmdTask (ANSC_HANDLE)pMyObject, hSrvSession ); - - CmdRequest.CurLineNumber = nRow - 1; + CmdRequest.CurLineNumber = (nRow > 0) ? (ULONG)(nRow - 1) : 0; if ( ulInputMode == SCLI_SHELL_INPUT_MODE_linemode && nRow > 0 ) { diff --git a/source/cosa/package/cli/components/ScliShell/scli_shell_help.c b/source/cosa/package/cli/components/ScliShell/scli_shell_help.c index fa7ad3592..4d0c6ccf5 100644 --- a/source/cosa/package/cli/components/ScliShell/scli_shell_help.c +++ b/source/cosa/package/cli/components/ScliShell/scli_shell_help.c @@ -2590,9 +2590,10 @@ ScliShoGetLastMatchedOptArg int nLast = -1; /*CID: 74816 Dereference after null check*/ - if ( pReqArgMatched || - ulReqArgCount == 0 || - (pReqArgMatched && pReqArgMatched[ulReqArgCount - 1].bMatched && pReqArgMatched[ulReqArgCount - 1].bValueMatched) ) + if (pReqArgMatched == NULL || ulReqArgCount == 0 || + (pReqArgMatched != NULL && + pReqArgMatched[ulReqArgCount - 1].bMatched && + pReqArgMatched[ulReqArgCount - 1].bValueMatched)) { int i; int nMaxTokenPos = -1; diff --git a/source/cosa/package/cli/components/ScliShell/scli_shell_process.c b/source/cosa/package/cli/components/ScliShell/scli_shell_process.c index fba7e369f..daadccbbf 100644 --- a/source/cosa/package/cli/components/ScliShell/scli_shell_process.c +++ b/source/cosa/package/cli/components/ScliShell/scli_shell_process.c @@ -2879,6 +2879,10 @@ ScliShoValidateCmdArgs ScliShoInitArgMatchResult(&pOptArgM[i]); } } + if ( !pReqArgM || !pOptArgM ) + { + goto EXIT; + } bMatched = ScliShoMatchCommand diff --git a/source/cosa/package/system/components/SysRepositoryDriver/sys_rdo_access.c b/source/cosa/package/system/components/SysRepositoryDriver/sys_rdo_access.c index c8d1c5b5d..33286b607 100644 --- a/source/cosa/package/system/components/SysRepositoryDriver/sys_rdo_access.c +++ b/source/cosa/package/system/components/SysRepositoryDriver/sys_rdo_access.c @@ -1147,12 +1147,16 @@ SysRdoGetRecord goto EXIT2; } +#if 0 + /* CID 178124: Logically dead code (DEADCODE) + At condition pThisFolder, the value of pThisFolder cannot be NULL */ else if ( !pThisFolder ) { pThisRecord = (PSYS_REPOSITORY_RECORD_OBJECT)NULL; goto EXIT2; } +#endif else if ( AnscTcGetTokenCount(pTokenChain) != 1 ) { pThisFolder->ReleaseAccess((ANSC_HANDLE)pThisFolder); @@ -1318,12 +1322,16 @@ SysRdoSetRecord goto EXIT2; } +#if 0 + /* CID 178125: Logically dead code (DEADCODE) + At condition pThisFolder, the value of pThisFolder cannot be NULL */ else if ( !pThisFolder ) { returnStatus = ANSC_STATUS_BAD_NAME; goto EXIT2; } +#endif else if ( AnscTcGetTokenCount(pTokenChain) != 1 ) { pThisFolder->ReleaseAccess((ANSC_HANDLE)pThisFolder); diff --git a/source/cosa/utilities/bsp_eng/bspeng_co_process.c b/source/cosa/utilities/bsp_eng/bspeng_co_process.c index ad2988449..edb02a0e2 100644 --- a/source/cosa/utilities/bsp_eng/bspeng_co_process.c +++ b/source/cosa/utilities/bsp_eng/bspeng_co_process.c @@ -808,9 +808,12 @@ BspTemplateObjParseComment if (*pBuf != '/') return FALSE; +#if 0 + /* CID: 340473: Logically Dead code*/ else if (*pBuf == '\0') return FALSE; +#endif ch = *(pBuf+1); diff --git a/source/util_api/ansc/AnscPlatform/ansc_checksum.c b/source/util_api/ansc/AnscPlatform/ansc_checksum.c index 77e3391cb..5721b6e42 100644 --- a/source/util_api/ansc/AnscPlatform/ansc_checksum.c +++ b/source/util_api/ansc/AnscPlatform/ansc_checksum.c @@ -130,7 +130,7 @@ AnscReplaceChecksum { tempUshort++; tempUchar += 1; - oldLength -= 1; + oldLength = (oldLength > 0) ? (oldLength - 1) : 0; } } @@ -164,7 +164,7 @@ AnscReplaceChecksum { tempUshort++; tempUchar += 1; - newLength -= 1; + newLength = (newLength > 0) ? (newLength - 1) : 0; } } diff --git a/source/util_api/ansc/AnscPlatform/ansc_task.c b/source/util_api/ansc/AnscPlatform/ansc_task.c index a420ddf31..7501f0699 100644 --- a/source/util_api/ansc/AnscPlatform/ansc_task.c +++ b/source/util_api/ansc/AnscPlatform/ansc_task.c @@ -352,7 +352,8 @@ AnscTaskRoutine2 AnscReleaseTask((ANSC_HANDLE)pTaskRecord); } - +#if 0 +CID: 559697: Unreachable. Above is an infinite loop. So logically Unreachable if ( g_bSafeParenting ) { AnscWaitAllChildTasks(pTaskRecord->Handle); @@ -361,6 +362,7 @@ AnscTaskRoutine2 AnscEraseTask(pTaskRecord); AnscLeaveTask(); +#endif } diff --git a/source/util_api/asn.1/components/asn1_x509/ansc_asn1_certificate.c b/source/util_api/asn.1/components/asn1_x509/ansc_asn1_certificate.c index 08ccb9fe5..46666a0a6 100644 --- a/source/util_api/asn.1/components/asn1_x509/ansc_asn1_certificate.c +++ b/source/util_api/asn.1/components/asn1_x509/ansc_asn1_certificate.c @@ -177,38 +177,38 @@ AnscAsn1GenSelfSignedCertificateWithCryptoAPI if( pPublicKeyInfo != NULL) { - pPublicKeyInfo->GenerateKey - ( - pPublicKeyInfo, - keyType, - &genParams - ); - } - - /* - * set the serial number, it supposed to be the MD5 fingerprint of public key - */ - pInteger = (PANSC_ASN1_INTEGER)pThisObject->GetSerialNumber(pThisObject); - pKeyObject = (PANSC_ASN1_OBJECT)pPublicKeyInfo->GetExtraChild(pPublicKeyInfo); - - if( pKeyObject != NULL) - { - if( ANSC_STATUS_SUCCESS == - AnscAsn1GetMD5FingerPrint(pKeyObject, &hash)) - { - /* make it as an unnegative value */ - if( hash.Value[0] > 0x80) - { - hash.Value[0] -= 0x80; - } - - pInteger->SetStringValue - ( - pInteger, - hash.Value, - hash.Length - ); - } + pPublicKeyInfo->GenerateKey + ( + pPublicKeyInfo, + keyType, + &genParams + ); + + /* + * set the serial number, it supposed to be the MD5 fingerprint of public key + */ + pInteger = (PANSC_ASN1_INTEGER)pThisObject->GetSerialNumber(pThisObject); + pKeyObject = (PANSC_ASN1_OBJECT)pPublicKeyInfo->GetExtraChild(pPublicKeyInfo); + + if( pKeyObject != NULL) + { + if( ANSC_STATUS_SUCCESS == + AnscAsn1GetMD5FingerPrint(pKeyObject, &hash)) + { + /* make it as an unnegative value */ + if( hash.Value[0] > 0x80) + { + hash.Value[0] -= 0x80; + } + + pInteger->SetStringValue + ( + pInteger, + hash.Value, + hash.Length + ); + } + } } /* @@ -306,40 +306,40 @@ AnscAsn1GenerateSelfSignedCertificate if( pPublicKeyInfo != NULL) { - pPublicKeyInfo->GenerateKey - ( - pPublicKeyInfo, - pAttrObject->KeyType, - hKeyPairHandle - ); - } - - /* - * set the serial number, it supposed to be the MD5 fingerprint of public key - */ - pInteger = (PANSC_ASN1_INTEGER)pThisObject->GetSerialNumber(pThisObject); - pKeyObject = (PANSC_ASN1_OBJECT)pPublicKeyInfo->GetExtraChild(pPublicKeyInfo); - - if( pKeyObject != NULL) - { - if( ANSC_STATUS_SUCCESS == - AnscAsn1GetMD5FingerPrint(pKeyObject, &hash)) - { - /* make it as an unnegative value */ - if( hash.Value[0] > 0x80) - { - hash.Value[0] -= 0x80; - } + pPublicKeyInfo->GenerateKey + ( + pPublicKeyInfo, + pAttrObject->KeyType, + hKeyPairHandle + ); + + /* + * set the serial number, it supposed to be the MD5 fingerprint of public key + */ + pInteger = (PANSC_ASN1_INTEGER)pThisObject->GetSerialNumber(pThisObject); + pKeyObject = (PANSC_ASN1_OBJECT)pPublicKeyInfo->GetExtraChild(pPublicKeyInfo); + + if( pKeyObject != NULL) + { + if( ANSC_STATUS_SUCCESS == + AnscAsn1GetMD5FingerPrint(pKeyObject, &hash)) + { + /* make it as an unnegative value */ + if( hash.Value[0] > 0x80) + { + hash.Value[0] -= 0x80; + } + + pInteger->SetStringValue + ( + pInteger, + hash.Value, + hash.Length + ); + } + } - pInteger->SetStringValue - ( - pInteger, - hash.Value, - hash.Length - ); - } } - /* * If subKeyIden extension is required; */ diff --git a/source/util_api/ccsp_msg_bus/ccsp_message_bus.c b/source/util_api/ccsp_msg_bus/ccsp_message_bus.c index d684b2cb2..585d9c725 100644 --- a/source/util_api/ccsp_msg_bus/ccsp_message_bus.c +++ b/source/util_api/ccsp_msg_bus/ccsp_message_bus.c @@ -2793,29 +2793,35 @@ CCSP_Message_Bus_Send_Str dbus_connection_unlock(conn); NewTimeout(&timeout, CCSP_MESSAGE_BUS_SEND_STR_TIMEOUT_SECONDS, 0); - if (reply) - { - ret = analyze_reply(message, reply, NULL); - } - else if(pthread_cond_timedwait(&cb_data->count_threshold_cv, &cb_data->count_mutex, &timeout) != 0) - { - dbus_pending_call_cancel(pcall); - // CcspTraceWarning(("<%s>: reply pthread_cond_timedwait timed out\n", __FUNCTION__)); + // Wait for the condition variable with a loop to handle spurious wakeups. + while (!cb_data->succeed) { + if (pthread_cond_timedwait(&cb_data->count_threshold_cv, &cb_data->count_mutex, &timeout) != 0) { + // Handle the timeout case + dbus_pending_call_cancel(pcall); + // Optionally log a timeout warning + // CcspTraceWarning(("<%s>: reply pthread_cond_timedwait timed out\n", __FUNCTION__)); + + //in case ccsp_msg_check_resp_sync is called between dbus_pending_call_cancel and pthread_cond_timedwait + // -> Cannot happen if it is a timed wait, increase the timeout amount instead. RTian 07/08/2013 + // CCSP_Msg_SleepInMilliSeconds(500); + break; + } + // If condition is met, proceed with reply processing + if (cb_data->succeed) { + dbus_connection_lock(conn); + reply = dbus_pending_call_steal_reply(pcall); + dbus_connection_unlock(conn); + if (reply) { + ret = analyze_reply(message, reply, NULL); + } + } + } + + // If reply received, analyze it + if (reply) { + ret = analyze_reply(message, reply, NULL); + } - //in case ccsp_msg_check_resp_sync is called between dbus_pending_call_cancel and pthread_cond_timedwait - // -> Cannot happen if it is a timed wait, increase the timeout amount instead. RTian 07/08/2013 - // CCSP_Msg_SleepInMilliSeconds(500); - } - else - { - dbus_connection_lock(conn); - reply = dbus_pending_call_steal_reply(pcall); - dbus_connection_unlock(conn); - if(reply) - { - ret = analyze_reply(message, reply, NULL); - } - } pthread_mutex_unlock(&cb_data->count_mutex); pthread_mutex_destroy(&cb_data->count_mutex); @@ -2932,27 +2938,35 @@ CCSP_Message_Bus_Send_Msg { ret = analyze_reply(message, reply, result); } - else if((rc = pthread_cond_timedwait(&cb_data->count_threshold_cv, &cb_data->count_mutex, &timeout)) != 0) - { - dbus_pending_call_cancel(pcall); - // CcspTraceWarning(("<%s>: pthread_cond_timedwait timeout\n", __FUNCTION__)); - - // in case ccsp_msg_check_resp_sync is called between dbus_pending_call_cancel and pthread_cond_timedwait - // CCSP_Msg_SleepInMilliSeconds(1000); + else + { + // Wait for the condition variable with a loop to handle spurious wakeups + while ((rc = pthread_cond_timedwait(&cb_data->count_threshold_cv, &cb_data->count_mutex, &timeout)) == 0) + { + // Check if the condition is met and process the reply + if (cb_data->succeed) { + dbus_connection_lock(conn); + reply = dbus_pending_call_steal_reply(pcall); + dbus_connection_unlock(conn); + if (reply) + { + ret = analyze_reply(message, reply, result); + break; // Exit after processing the reply + } + } + } + + // If timeout occurs or condition is not met + if (rc != 0) { + dbus_pending_call_cancel(pcall); + // CcspTraceWarning(("<%s>: pthread_cond_timedwait timeout\n", __FUNCTION__)); + + // in case ccsp_msg_check_resp_sync is called between dbus_pending_call_cancel and pthread_cond_timedwait + // CCSP_Msg_SleepInMilliSeconds(1000); + ret = CCSP_MESSAGE_BUS_TIMEOUT; + } + } - ret = CCSP_MESSAGE_BUS_TIMEOUT; - } - else - { - dbus_connection_lock(conn); - reply = dbus_pending_call_steal_reply(pcall); - dbus_connection_unlock(conn); - if (reply) - { - ret = analyze_reply(message, reply, result); - } - else {} // do nothing - } pthread_mutex_unlock(&cb_data->count_mutex); pthread_mutex_destroy(&cb_data->count_mutex); diff --git a/source/util_api/web/components/WebVirtualHost/web_vho_process.c b/source/util_api/web/components/WebVirtualHost/web_vho_process.c index cc4ea3983..e1613c814 100644 --- a/source/util_api/web/components/WebVirtualHost/web_vho_process.c +++ b/source/util_api/web/components/WebVirtualHost/web_vho_process.c @@ -867,6 +867,9 @@ WebVhoGetResourcePath break; } } +#if 0 + /* Coverity CId:340277 - Logically dead code + * At condition pReqInfo->RequestUri.Type == 2UL, the value of pReqInfo->RequestUri.Type must be equal to 4. */ else if ( pReqInfo->RequestUri.Type == HTTP_URI_TYPE_ABSOLUTE_URI ) { if ( !strcasecmp(pHttpHfoReferer->ReferrerUri.HostName,pReqInfo->RequestUri.HostName) == 0 ) @@ -874,6 +877,7 @@ WebVhoGetResourcePath break; } } +#endif else { break;