From 057e34c0fd7099b9f63a3aad3327a3051fe84993 Mon Sep 17 00:00:00 2001 From: "wn.jang" Date: Thu, 8 Oct 2020 19:00:14 +0900 Subject: [PATCH] Fix crash when connection was null JIRA - https://code.sec.samsung.net/jira/browse/TSIX-6919 callstack was as following. Callstack Information (PID:11475) Call Stack Count: 24 0: gsignal + 0x9c (0xb63d3470) [/usr/lib/libc-2.30.so] + 0x30470 1: abort + 0x10c (0xb63bd780) [/usr/lib/libc-2.30.so] + 0x1a780 2: _dbus_abort + 0x68 (0xa6a356e0) [/usr/lib/libdbus-1.so.3.19.11] + 0x396e0 3: _dbus_warn_check_failed + 0x88 (0xa6a2a128) [/usr/lib/libdbus-1.so.3.19.11] + 0x2e128 4: _dbus_warn_return_if_fail + 0x30 (0xa6a2a830) [/usr/lib/libdbus-1.so.3.19.11] + 0x2e830 5: dbus_connection_send_with_reply_and_block + 0x214 (0xa6a0ef8c) [/usr/lib/libdbus-1.so.3.19.11] + 0x12f8c 6: stt_dbus_request_hello + 0x58 (0xa6ab8c75) [/usr/lib/libstt.so] + 0xdc75 Change-Id: I182bda3b921a63a6c43916fe1acb968fb3ebe505 --- client/stt_dbus.c | 123 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 64 insertions(+), 59 deletions(-) diff --git a/client/stt_dbus.c b/client/stt_dbus.c index 20c68ef..39287f1 100644 --- a/client/stt_dbus.c +++ b/client/stt_dbus.c @@ -863,76 +863,81 @@ int stt_dbus_request_hello(int uid) DBusMessage* result_msg = NULL; int result = 0; - if (g_conn_sender) { - if (NULL != client) { - __stt_dbus_service_free(); - - if (NULL == client->current_engine_id) { - /* Default engine */ - g_server_service_name = strdup(STT_SERVER_SERVICE_NAME); - if (NULL == g_server_service_name) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE - return STT_ERROR_OUT_OF_MEMORY; - } - g_server_service_object = strdup(STT_SERVER_SERVICE_OBJECT_PATH); - if (NULL == g_server_service_name) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); - return STT_ERROR_OUT_OF_MEMORY; - } - g_server_service_interface = strdup(STT_SERVER_SERVICE_INTERFACE); - if (NULL == g_server_service_name) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); - return STT_ERROR_OUT_OF_MEMORY; - } + if (NULL == g_conn_sender) { + SLOG(LOG_WARN, TAG_STTC, "[WARN] dbus connection handle is null (%p)", g_conn_sender); //LCOV_EXCL_LINE + result = stt_dbus_reconnect(); + if (0 != result) + return STT_ERROR_OPERATION_FAILED; + } - msg = dbus_message_new_method_call( - STT_SERVER_SERVICE_NAME, - STT_SERVER_SERVICE_OBJECT_PATH, - STT_SERVER_SERVICE_INTERFACE, - STT_METHOD_HELLO); - } else { - /* Get service name, object, interface */ - SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] current_engine_id: %s", client->current_engine_id); //LCOV_EXCL_LINE + if (NULL != client) { + __stt_dbus_service_free(); - g_server_service_name = __stt_get_service_name(client->current_engine_id); - g_server_service_object = __stt_get_service_object(client->current_engine_id); - g_server_service_interface = __stt_get_service_interface(client->current_engine_id); + if (NULL == client->current_engine_id) { + /* Default engine */ + g_server_service_name = strdup(STT_SERVER_SERVICE_NAME); + if (NULL == g_server_service_name) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); //LCOV_EXCL_LINE + return STT_ERROR_OUT_OF_MEMORY; + } + g_server_service_object = strdup(STT_SERVER_SERVICE_OBJECT_PATH); + if (NULL == g_server_service_name) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); + return STT_ERROR_OUT_OF_MEMORY; + } + g_server_service_interface = strdup(STT_SERVER_SERVICE_INTERFACE); + if (NULL == g_server_service_name) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] Fail to allocate memory"); + return STT_ERROR_OUT_OF_MEMORY; + } - if (NULL == g_server_service_name || NULL == g_server_service_object || NULL == g_server_service_interface) { - SLOG(LOG_ERROR, TAG_STTC, "[ERROR] dbus service info invalid"); //LCOV_EXCL_LINE - return STT_ERROR_OPERATION_FAILED; - } + msg = dbus_message_new_method_call( + STT_SERVER_SERVICE_NAME, + STT_SERVER_SERVICE_OBJECT_PATH, + STT_SERVER_SERVICE_INTERFACE, + STT_METHOD_HELLO); + } else { + /* Get service name, object, interface */ + SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] current_engine_id: %s", client->current_engine_id); //LCOV_EXCL_LINE - SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] service name: %s, object path: %s, interface: %s", g_server_service_name, g_server_service_object, g_server_service_interface); //LCOV_EXCL_LINE + g_server_service_name = __stt_get_service_name(client->current_engine_id); + g_server_service_object = __stt_get_service_object(client->current_engine_id); + g_server_service_interface = __stt_get_service_interface(client->current_engine_id); - /* Custom engine */ - is_exist = dbus_bus_name_has_owner(g_conn_sender, g_server_service_name, &err); - SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] is there dbus name has owner??: %s (g_server_service_name: %s)", (is_exist == TRUE) ? "True" : "False", g_server_service_name); //LCOV_EXCL_LINE + if (NULL == g_server_service_name || NULL == g_server_service_object || NULL == g_server_service_interface) { + SLOG(LOG_ERROR, TAG_STTC, "[ERROR] dbus service info invalid"); //LCOV_EXCL_LINE + return STT_ERROR_OPERATION_FAILED; + } - if (TRUE == is_exist) { - SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] dbus: is_exist: True"); //LCOV_EXCL_LINE - msg = dbus_message_new_method_call( - g_server_service_name, - g_server_service_object, - g_server_service_interface, - STT_METHOD_HELLO); - } else { - SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] dbus: is_exist: False"); //LCOV_EXCL_LINE - msg = dbus_message_new_method_call( - STT_SERVER_CUSTOM_SERVICE_NAME, - STT_SERVER_CUSTOM_SERVICE_OBJECT_PATH, - STT_SERVER_CUSTOM_SERVICE_INTERFACE, - STT_METHOD_HELLO); - } + SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] service name: %s, object path: %s, interface: %s", g_server_service_name, g_server_service_object, g_server_service_interface); //LCOV_EXCL_LINE + + /* Custom engine */ + is_exist = dbus_bus_name_has_owner(g_conn_sender, g_server_service_name, &err); + SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] is there dbus name has owner??: %s (g_server_service_name: %s)", (is_exist == TRUE) ? "True" : "False", g_server_service_name); //LCOV_EXCL_LINE + + if (TRUE == is_exist) { + SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] dbus: is_exist: True"); //LCOV_EXCL_LINE + msg = dbus_message_new_method_call( + g_server_service_name, + g_server_service_object, + g_server_service_interface, + STT_METHOD_HELLO); + } else { + SLOG(LOG_DEBUG, TAG_STTC, "[DBUS] dbus: is_exist: False"); //LCOV_EXCL_LINE + msg = dbus_message_new_method_call( + STT_SERVER_CUSTOM_SERVICE_NAME, + STT_SERVER_CUSTOM_SERVICE_OBJECT_PATH, + STT_SERVER_CUSTOM_SERVICE_INTERFACE, + STT_METHOD_HELLO); } } } if (NULL == msg) { -// SLOG(LOG_ERROR, TAG_STTC, ">>>> Request stt hello : Fail to make message"); - result = stt_dbus_reconnect(); - if (0 != result) - return STT_ERROR_OPERATION_FAILED; + SLOG(LOG_ERROR, TAG_STTC, ">>>> Request stt hello : Fail to make message"); + return STT_ERROR_OPERATION_FAILED; + } else { + SLOG(LOG_DEBUG, TAG_STTC, ">>>> Request stt hello : uid(%d)", uid); } if (g_conn_sender) { -- 2.7.4