diff --git a/source/db/wifi_db_apis.c b/source/db/wifi_db_apis.c index daedab38c..8c1e22aa1 100644 --- a/source/db/wifi_db_apis.c +++ b/source/db/wifi_db_apis.c @@ -2655,7 +2655,7 @@ extern const char* get_passpoint_json_by_vap_name(const char* vap_name); extern const char* get_anqp_json_by_vap_name(const char* vap_name); extern void reset_passpoint_json(const char* vap_name); extern void reset_anqp_json(const char* vap_name); -extern int get_wifi_last_reboot_reason_psm_value(char *last_reboot_reason); +extern int get_wifi_last_reboot_reason_psm_value(char *last_reboot_reason, size_t len); void wifidb_reset_macfilter_hashmap() { @@ -5520,10 +5520,12 @@ void *start_wifidb_func(void *arg) get_bus_descriptor()->bus_data_free_fn(&data); return NULL; } - strncpy(last_reboot_reason, (char *)data.raw_data.bytes, data.raw_data_len); + strncpy(last_reboot_reason, (char *)data.raw_data.bytes, + sizeof(last_reboot_reason) - 1); + last_reboot_reason[sizeof(last_reboot_reason) - 1] = '\0'; get_bus_descriptor()->bus_data_free_fn(&data); } else { - get_wifi_last_reboot_reason_psm_value(last_reboot_reason); + get_wifi_last_reboot_reason_psm_value(last_reboot_reason, sizeof(last_reboot_reason)); } wifi_util_info_print(WIFI_DB, "%s:%d last_reboot_reason:%s \n", __func__, __LINE__, last_reboot_reason); @@ -9741,19 +9743,25 @@ int get_wifi_db_psm_enable_status(bool *wifi_psm_db_enabled) return RETURN_OK; } -int get_wifi_last_reboot_reason_psm_value(char *last_reboot_reason) +int get_wifi_last_reboot_reason_psm_value(char *last_reboot_reason, size_t len) { char *str = NULL; char strValue[256] = {0}; wifi_ccsp_desc_t *p_ccsp_desc = &get_wificcsp_obj()->desc; + if (last_reboot_reason == NULL || len == 0) + { + wifi_util_error_print(WIFI_MGR, "%s:%d Invalid parameters\n", __func__, __LINE__); + return RETURN_ERR; + } + memset(strValue, 0, sizeof(strValue)); str = p_ccsp_desc->psm_get_value_fn(LAST_REBOOT_REASON_NAMESPACE, strValue, sizeof(strValue)); if (str != NULL) { - strcpy(last_reboot_reason, str); + snprintf(last_reboot_reason, len, "%s", str); wifi_util_dbg_print(WIFI_MGR,"str is %s and last_reboot_reason is %s\n", str, last_reboot_reason); } else { - wifi_util_error_print(WIFI_MGR,"%s:%d last_reboot_reason:%s \r\n", __func__, __LINE__, last_reboot_reason); + wifi_util_error_print(WIFI_MGR,"%s:%d PSM get value returned NULL\n", __func__, __LINE__); return RETURN_ERR; } @@ -9811,7 +9819,7 @@ int get_all_param_from_psm_and_set_into_db(void) } } else { get_wifi_db_psm_enable_status(&wifi_psm_db_enabled); - get_wifi_last_reboot_reason_psm_value(last_reboot_reason); + get_wifi_last_reboot_reason_psm_value(last_reboot_reason, sizeof(last_reboot_reason)); } wifi_util_info_print(WIFI_MGR, "%s psm:%d last_reboot_reason:%s \n", __func__, diff --git a/source/dml/tr_181/ml/cosa_wifi_dml.c b/source/dml/tr_181/ml/cosa_wifi_dml.c index 45a0bc033..e344c5437 100755 --- a/source/dml/tr_181/ml/cosa_wifi_dml.c +++ b/source/dml/tr_181/ml/cosa_wifi_dml.c @@ -8667,7 +8667,7 @@ Security_GetParamStringValue /* collect value */ char buf[32] = {0}; if ( AnscSizeOfString(buf) < *pUlSize) { - getSecurityStringFromInt(pcfg->mode, buf); + getSecurityStringFromInt(pcfg->mode, buf, sizeof(buf)); AnscCopyString(pValue, buf); } else { *pUlSize = AnscSizeOfString(buf) + 1; diff --git a/source/dml/tr_181/sbapi/cosa_wifi_apis.c b/source/dml/tr_181/sbapi/cosa_wifi_apis.c index 32362f114..ec49475dc 100644 --- a/source/dml/tr_181/sbapi/cosa_wifi_apis.c +++ b/source/dml/tr_181/sbapi/cosa_wifi_apis.c @@ -432,21 +432,34 @@ INT getTxDataRateFromInt(wifi_bitrate_t DataTxRate, char *DataTxRateStr) return 0; } -INT getSecurityStringFromInt(wifi_security_modes_t securityType, char *securityName) +INT getSecurityStringFromInt(wifi_security_modes_t securityType, char *securityName, size_t bufSize) { unsigned int i; + size_t currentLen; + + if (securityName == NULL || bufSize == 0) + { + CcspWifiTrace(("RDK_LOG_ERROR, %s Invalid argument\n", __func__)); + return 0; + } + for (i = 0 ; i < ARRAY_SZ(wifiSecMap) ; ++i) { if(securityType == wifiSecMap[i].halSecCfgMethod) { - if (AnscSizeOfString(securityName) != 0) + currentLen = AnscSizeOfString(securityName); + if (currentLen != 0) { - strcat(securityName, ","); - strcat(securityName, wifiSecMap[i].wifiSecType); + if (currentLen >= bufSize) + { + CcspWifiTrace(("RDK_LOG_ERROR, %s buffer full, cannot append security type\n", __func__)); + break; + } + snprintf(securityName + currentLen, bufSize - currentLen, ",%s", wifiSecMap[i].wifiSecType); } else { - strcpy(securityName, wifiSecMap[i].wifiSecType); + snprintf(securityName, bufSize, "%s", wifiSecMap[i].wifiSecType); } } }