From: dyamy-lee Date: Wed, 27 Nov 2024 08:19:56 +0000 (+0900) Subject: Change timing of initializing and cleanning up libxml Parser X-Git-Tag: accepted/tizen/8.0/unified/20250324.145916~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F85%2F315385%2F1;p=platform%2Fcore%2Fuifw%2Ftts.git Change timing of initializing and cleanning up libxml Parser Issue : crash when xmlParseFile is called Solution : The function xmlParseFile() parses XML files. If the internal of libxml2 is corrupted due to missing initialization, a crash can be occurred. But, xmlInitParser is a global initialization function that only need to be called once for the entire program. Therefore, this patch modified the structure to manage initialization before any xmlParseFile usage. Change-Id: Ie7fc14e4d923e2dd72d938f0f4af349359f13365 --- diff --git a/common/tts_config_mgr.c b/common/tts_config_mgr.c index f95a228c..c487c630 100644 --- a/common/tts_config_mgr.c +++ b/common/tts_config_mgr.c @@ -770,8 +770,12 @@ static Eina_Bool tts_config_mgr_inotify_event_cb(void* data, Ecore_Fd_Handler *f SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] IN_DELETE_SELF event"); tts_parser_unload_config(); + tts_parser_cleanup_xml(); tts_parser_reset(); - tts_parser_load_config(); + tts_parser_initialize_xml(); + if (0 != tts_parser_load_config()) { + tts_parser_cleanup_xml(); + } } else { SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Undefined event (0x%x)", event.mask); } @@ -1328,10 +1332,13 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_ SLOG(LOG_INFO, TAG_TTSCONFIG, "Client type : %d", client_type); g_client_type |= client_type; + tts_parser_initialize_xml(); + if (0 != __tts_config_mgr_get_engine_info()) { SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get engine info"); release_config_client(uid); __tts_config_release_engine(); + tts_parser_cleanup_xml(); return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND; } @@ -1341,6 +1348,7 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse configure information"); release_config_client(uid); __tts_config_release_engine(); + tts_parser_cleanup_xml(); return TTS_CONFIG_ERROR_OPERATION_FAILED; } tts_config_s config_info; @@ -1348,6 +1356,8 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_ SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to get configure information"); release_config_client(uid); __tts_config_release_engine(); + tts_parser_unload_config(); + tts_parser_cleanup_xml(); return TTS_CONFIG_ERROR_OPERATION_FAILED; } @@ -1357,6 +1367,7 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_ release_config_client(uid); __tts_config_release_engine(); tts_parser_unload_config(); + tts_parser_cleanup_xml(); return TTS_CONFIG_ERROR_ENGINE_NOT_FOUND; } @@ -1373,6 +1384,7 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_ release_config_client(uid); __tts_config_release_engine(); tts_parser_unload_config(); + tts_parser_cleanup_xml(); return TTS_CONFIG_ERROR_OPERATION_FAILED; } @@ -1388,6 +1400,7 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_ release_config_client(uid); __tts_config_release_engine(); tts_parser_unload_config(); + tts_parser_cleanup_xml(); return TTS_CONFIG_ERROR_OPERATION_FAILED; } } else { @@ -1419,6 +1432,7 @@ int tts_config_mgr_initialize(unsigned int uid, tts_config_client_type_e client_ release_config_client(uid); __tts_config_release_engine(); tts_parser_unload_config(); + tts_parser_cleanup_xml(); return TTS_CONFIG_ERROR_OPERATION_FAILED; } @@ -1454,6 +1468,7 @@ int tts_config_mgr_finalize(unsigned int uid, tts_config_client_type_e client_ty __tts_config_release_engine(); tts_parser_unload_config(); + tts_parser_cleanup_xml(); __tts_config_mgr_unregister_engine_config_updated_event(); diff --git a/common/tts_config_parser.c b/common/tts_config_parser.c index dad135e7..2813a643 100644 --- a/common/tts_config_parser.c +++ b/common/tts_config_parser.c @@ -55,6 +55,23 @@ char g_language[128] = {0,}; static tts_config_s* g_config_info = NULL; static pthread_mutex_t g_config_info_mutex = PTHREAD_MUTEX_INITIALIZER; +static bool is_libxml_initialized = false; + +void tts_parser_initialize_xml(void) { + if (!is_libxml_initialized) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Initialize xmlParser"); + xmlInitParser(); + is_libxml_initialized = true; + } +} + +void tts_parser_cleanup_xml(void) { + if (is_libxml_initialized) { + SLOG(LOG_ERROR, TAG_TTSCONFIG, "[DEBUG] Cleanup xmlParser"); + xmlCleanupParser(); + is_libxml_initialized = false; + } +} int tts_parser_get_engine_info(const char* path, tts_engine_info_s** engine_info) { @@ -360,14 +377,10 @@ int tts_parser_load_config(void) xmlNodePtr cur = NULL; bool is_default_open = false; - /* For Thread safety */ - xmlInitParser(); - if (0 != access(TTS_CONFIG, F_OK)) { doc = xmlParseFile(TTS_DEFAULT_CONFIG); if (doc == NULL) { SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG); - xmlCleanupParser(); return -1; } is_default_open = true; @@ -387,7 +400,6 @@ int tts_parser_load_config(void) doc = xmlParseFile(TTS_DEFAULT_CONFIG); if (NULL == doc) { SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Fail to parse file error : %s", TTS_DEFAULT_CONFIG); - xmlCleanupParser(); return -1; } is_default_open = true; @@ -401,7 +413,6 @@ int tts_parser_load_config(void) SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc); xmlFreeDoc(doc); doc = NULL; - xmlCleanupParser(); return -1; } @@ -409,7 +420,6 @@ int tts_parser_load_config(void) SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] The wrong type, root node is NOT %s. doc(%p)", TTS_TAG_CONFIG_BASE_TAG, doc); xmlFreeDoc(doc); doc = NULL; - xmlCleanupParser(); return -1; } @@ -418,7 +428,6 @@ int tts_parser_load_config(void) SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Empty document(%p)", doc); xmlFreeDoc(doc); doc = NULL; - xmlCleanupParser(); return -1; } @@ -429,7 +438,6 @@ int tts_parser_load_config(void) SLOG(LOG_ERROR, TAG_TTSCONFIG, "[ERROR] Out of memory(%p)", doc); xmlFreeDoc(doc); doc = NULL; - xmlCleanupParser(); return -1; } @@ -598,8 +606,6 @@ int tts_parser_unload_config(void) g_config_info = NULL; } pthread_mutex_unlock(&g_config_info_mutex); - - xmlCleanupParser(); return 0; } diff --git a/common/tts_config_parser.h b/common/tts_config_parser.h index a39d935b..afc078e8 100644 --- a/common/tts_config_parser.h +++ b/common/tts_config_parser.h @@ -91,6 +91,10 @@ int tts_parser_copy_xml(const char* original, const char* destination); int tts_parser_reset(); +void tts_parser_initialize_xml(void); + +void tts_parser_cleanup_xml(void); + #ifdef __cplusplus } #endif