From 3d8634c55cfbd8d91ce932e8827ec3cf620a1bfb Mon Sep 17 00:00:00 2001 From: rirfha948 Date: Mon, 8 Dec 2025 04:46:07 +0000 Subject: [PATCH 1/3] RDKB-62620: Coverity Cleanup for CcspCommonLibrary Reason for change: Fixes for CcspCommonLibrary Coverity Fixes Category: Integer Overflow Severity: MEDIUM Test Procedure: - TBD Risks: None Priority: P3 Signed-off-by: rirfha948 --- .../components/CCSP_AliasMgr/ccsp_alias_mgr_base.c | 4 ++-- .../DslhCpeController/dslh_cpeco_control.c | 13 +++++++++++-- .../helper/messagebus_interface_helper.c | 14 +++++++------- .../cli/components/ScliShell/scli_shell_exec.c | 3 +-- .../cli/components/ScliShell/scli_shell_help.c | 7 ++++--- .../SysRepositoryDriver/sys_rdo_access.c | 8 ++++++++ source/cosa/utilities/bsp_eng/bspeng_co_process.c | 3 +++ source/util_api/ansc/AnscPlatform/ansc_checksum.c | 4 ++-- .../components/WebVirtualHost/web_vho_process.c | 4 ++++ 9 files changed, 42 insertions(+), 18 deletions(-) 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 759c48289..6817c32c9 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 @@ -1342,8 +1342,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_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/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/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; From 6c7fac3305fa9593569a7a710013cbced570d9f9 Mon Sep 17 00:00:00 2001 From: ksures101 Date: Fri, 12 Dec 2025 00:38:39 +0530 Subject: [PATCH 2/3] RDKB-62302, RDKB-62690, RDKB-62687, RDKB-62732: Dibbler server and GUI issues (#55) Reason for change: 1. Dibbler server is not running. 2. Local IP Configuration page is not accessible, and IPv6 details are missing. Test Procedure: 1. Check dibbler is running or not "ps | grep dibbler" 2. Check local IP page is accessible and IPV6 details are present or not in xfinity network page Risks: None Signed-off-by: kavyachowdahalli_suresh@comcast.com Signed-off-by: kavyachowdahalli_suresh@comcast.com --- source/dm_pack/dm_pack_xml_helper.c | 106 +++++++--------------------- 1 file changed, 26 insertions(+), 80 deletions(-) diff --git a/source/dm_pack/dm_pack_xml_helper.c b/source/dm_pack/dm_pack_xml_helper.c index 3e0b1a802..ab357d108 100644 --- a/source/dm_pack/dm_pack_xml_helper.c +++ b/source/dm_pack/dm_pack_xml_helper.c @@ -54,7 +54,6 @@ #define W_DEFAULT -1 #define N_DEFAULT -1 -#define PARAM_TYPE_COUNT (sizeof(paramName) / sizeof(paramName[0])) /*CID: 280130, 280150 and 280152 fix for Resource leak*/ typedef enum funcNameId { func_GetEntryCount, @@ -218,24 +217,14 @@ PANSC_XML_DOM_NODE_OBJECT DMPackCreateObject(PANSC_XML_DOM_NODE_OBJECT P, int ty { PANSC_XML_DOM_NODE_OBJECT P1 = NULL; /*CID: 280130 fix for Resource leak*/ - if (!P || !name || (unsigned int)type >= PARAM_TYPE_COUNT) - return NULL; - P1 = DMPackCreateNode(P,"object",0,0); if (!P1) - return NULL; - - if (DMPackCreateNode(P1, "name", name, 0) == NULL) { - return NULL; - } - - if (DMPackCreateNode(P1, "objectType", objectType[type], objectTypeLen[type]) == NULL) { - return NULL; - } + return P1; - if (maxInstance && DMPackCreateNode(P1, "maxInstance", maxInstance, 0) == NULL) { - return NULL; - } + DMPackCreateNode(P1, "name", name, 0); + DMPackCreateNode(P1, "objectType", objectType[type], objectTypeLen[type]); + if (maxInstance) + DMPackCreateNode(P1, "maxInstance", maxInstance, 0); pCurrentFunctionsNode=0; return P1; } @@ -285,82 +274,39 @@ void DMPackCreateParam(PANSC_XML_DOM_NODE_OBJECT P, char* name, int typeId) { PANSC_XML_DOM_NODE_OBJECT P1 = NULL; /* CID:280150 fix for Resource leak */ - if (!P || !name || (unsigned int)typeId >= PARAM_TYPE_COUNT) - { - return; - } - P1 = DMPackCreateNode(P, "parameter", 0, 0); if (!P1) return; - if (DMPackCreateNode(P1, "name", name, 0) == NULL) { - return; - } - - if (DMPackCreateNode(P1, "type", paramName[typeId], paramNameLen[typeId]) == NULL) { - return; - } - - if (DMPackCreateNode(P1, "syntax", paramSyntax[typeId], paramSyntaxLen[typeId]) == NULL) { - return; - } + DMPackCreateNode(P1, "name", name, 0); + DMPackCreateNode(P1, "type", paramName[typeId], paramNameLen[typeId]); + DMPackCreateNode(P1, "syntax", paramSyntax[typeId], paramSyntaxLen[typeId]); } void DMPackCreateParamEx(PANSC_XML_DOM_NODE_OBJECT P, char* name, int typeId, char* type, char* syntax, int writable, int notify) { PANSC_XML_DOM_NODE_OBJECT P1 = NULL; /* CID:280152 fix for Resource leak */ - if (!P || !name) - { - return; - } - P1 = DMPackCreateNode(P,"parameter",0,0); if (!P1) return; - if (DMPackCreateNode(P1,"name",name,0) == NULL) { - return; - } - - if (type) { - if (DMPackCreateNode(P1,"type",type,0) == NULL) { - return; - } - } else if (typeId >= 0 && (unsigned int)typeId < PARAM_TYPE_COUNT) { - if (DMPackCreateNode(P1,"type",paramName[typeId],paramNameLen[typeId]) == NULL) { - return; - } - } - - if (syntax) { - if (DMPackCreateNode(P1,"syntax",syntax,0) == NULL) { - return; - } - } else if (typeId >= 0 && (unsigned int)typeId < PARAM_TYPE_COUNT) { - if (DMPackCreateNode(P1,"syntax",paramSyntax[typeId],paramSyntaxLen[typeId]) == NULL) { - return; - } - } - - if (writable == 0) { - if (DMPackCreateNode(P1,"writable","false",5) == NULL) { - return; - } - } else if (writable == 1) { - if (DMPackCreateNode(P1,"writable","true",4) == NULL) { - return; - } - } - - if (notify == 0) { - if (DMPackCreateNode(P1,"notify","off",3) == NULL) { - return; - } - } else if (notify == 1) { - if (DMPackCreateNode(P1,"notify","on",2) == NULL) { - return; /* CID 280129 fix */ - } - } + DMPackCreateNode(P1,"name",name,0); + + if(type) + DMPackCreateNode(P1,"type",type,0); + else + DMPackCreateNode(P1,"type",paramName[typeId],paramNameLen[typeId]); + if(syntax) + DMPackCreateNode(P1,"syntax",syntax,0); + else + DMPackCreateNode(P1,"syntax",paramSyntax[typeId],paramSyntaxLen[typeId]); + if(writable == 0) + DMPackCreateNode(P1,"writable","false",5); + else if(writable == 1) + DMPackCreateNode(P1,"writable","true",4); + if(notify == 0) + DMPackCreateNode(P1,"notify","off",3); + else if(notify == 1) + DMPackCreateNode(P1,"notify","on",2); /* CID 280129 fix */ } void DMPackCreateParamTSWN(PANSC_XML_DOM_NODE_OBJECT P,char* name,char* T,char* S,int W,int N) { From c19df0a593ff9733936f79e717047287dc848b3f Mon Sep 17 00:00:00 2001 From: rirfha948 Date: Fri, 12 Dec 2025 04:16:39 +0000 Subject: [PATCH 3/3] RDKB-62620: Coverity Cleanup for CcspCommonLibrary Reason for change: Fixes for CcspCommonLibrary Coverity Fixes Category: Integer Overflow Severity: MEDIUM Test Procedure: - TBD Risks: None Priority: P3 Signed-off-by: rirfha948 --- .../cli/components/ScliShell/scli_shell_bic.c | 10 +- .../components/ScliShell/scli_shell_process.c | 4 + source/util_api/ansc/AnscPlatform/ansc_task.c | 4 +- .../asn1_x509/ansc_asn1_certificate.c | 128 +++++++++--------- .../util_api/ccsp_msg_bus/ccsp_message_bus.c | 98 ++++++++------ 5 files changed, 135 insertions(+), 109 deletions(-) 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_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/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);