From bee558fe9bc6722923c15ed36fa8e9dd401b79b0 Mon Sep 17 00:00:00 2001 From: Suyeon Hwang Date: Mon, 20 Dec 2021 13:53:26 +0900 Subject: [PATCH] Get UID from list using tts_config_client_s structure Current code converts the type of element as integer. However, the element of the list is instance of tts_config_client_s structure. Because the first member of the structure is uid, so current code has no problem until now. But this can occur problem if the type of uid or the order of member is changed. To solve this problem, this patch changes the type from integer to the structure. This can provide safe access to member. Change-Id: I168011529efec4a59a1a1abc8b7d203e412a4972 Signed-off-by: Suyeon Hwang --- common/tts_config_mgr.c | 64 ++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/common/tts_config_mgr.c b/common/tts_config_mgr.c index 15e57410..8a208732 100644 --- a/common/tts_config_mgr.c +++ b/common/tts_config_mgr.c @@ -1133,65 +1133,63 @@ static int __tts_config_mgr_unregister_engine_config_updated_event() int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_type) { - GSList *iter = NULL; - int* get_uid; - tts_config_client_s* temp_client = NULL; + tts_config_client_s* new_client = NULL; /* Register uid */ if (0 < g_slist_length(g_config_client_list)) { /* Check uid */ - iter = g_slist_nth(g_config_client_list, 0); + GSList *iter = g_slist_nth(g_config_client_list, 0); while (NULL != iter) { - get_uid = iter->data; + tts_config_client_s* client = (tts_config_client_s*)iter->data; - if (uid == *get_uid) { + if (NULL != client && uid == client->uid) { SECURE_SLOG(LOG_WARN, TAG_TTSCONFIG, "[CONFIG] uid(%u) has already registered", uid); - return 0; + return TTS_CONFIG_ERROR_NONE; } iter = g_slist_next(iter); } - temp_client = (tts_config_client_s*)calloc(1, sizeof(tts_config_client_s)); - if (NULL == temp_client) { + new_client = (tts_config_client_s*)calloc(1, sizeof(tts_config_client_s)); + if (NULL == new_client) { SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to allocate memory"); return TTS_CONFIG_ERROR_OUT_OF_MEMORY; } - temp_client->uid = uid; - temp_client->engine_cb = NULL; - temp_client->voice_cb = NULL; - temp_client->speech_cb = NULL; - temp_client->pitch_cb = NULL; - temp_client->screen_cb = NULL; - temp_client->bg_volume_ratio_cb = NULL; - temp_client->user_data = NULL; - temp_client->screen_user_data = NULL; + new_client->uid = uid; + new_client->engine_cb = NULL; + new_client->voice_cb = NULL; + new_client->speech_cb = NULL; + new_client->pitch_cb = NULL; + new_client->screen_cb = NULL; + new_client->bg_volume_ratio_cb = NULL; + new_client->user_data = NULL; + new_client->screen_user_data = NULL; - g_config_client_list = g_slist_append(g_config_client_list, temp_client); + g_config_client_list = g_slist_append(g_config_client_list, new_client); SECURE_SLOG(LOG_WARN, TAG_TTSCONFIG, "[CONFIG] Add uid(%u) but config has already initialized", uid); SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type : %d", client_type); g_client_type |= client_type; - return 0; + return TTS_CONFIG_ERROR_NONE; } else { - temp_client = (tts_config_client_s*)calloc(1, sizeof(tts_config_client_s)); - if (NULL == temp_client) { + new_client = (tts_config_client_s*)calloc(1, sizeof(tts_config_client_s)); + if (NULL == new_client) { SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to allocate memory"); return TTS_CONFIG_ERROR_OUT_OF_MEMORY; } - temp_client->uid = uid; - temp_client->engine_cb = NULL; - temp_client->voice_cb = NULL; - temp_client->speech_cb = NULL; - temp_client->pitch_cb = NULL; - temp_client->screen_cb = NULL; - temp_client->bg_volume_ratio_cb = NULL; - temp_client->user_data = NULL; - temp_client->screen_user_data = NULL; - - g_config_client_list = g_slist_append(g_config_client_list, temp_client); + new_client->uid = uid; + new_client->engine_cb = NULL; + new_client->voice_cb = NULL; + new_client->speech_cb = NULL; + new_client->pitch_cb = NULL; + new_client->screen_cb = NULL; + new_client->bg_volume_ratio_cb = NULL; + new_client->user_data = NULL; + new_client->screen_user_data = NULL; + + g_config_client_list = g_slist_append(g_config_client_list, new_client); } if (0 != access(TTS_CONFIG_BASE, F_OK)) { -- 2.34.1