From: jusung son Date: Mon, 11 Sep 2017 08:26:48 +0000 (+0900) Subject: Fix socket exception handling X-Git-Tag: accepted/tizen/4.0/unified/20170920.081435~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F67%2F148967%2F2;p=platform%2Fcore%2Fappfw%2Fmessage-port.git Fix socket exception handling - Check the unprocessed data Change-Id: Icaeef2b79ab70b556a2ca4800f6c1d876b0b7a3e Signed-off-by: jusung son --- diff --git a/src/message_port_common.c b/src/message_port_common.c index 4758751..2b9d768 100755 --- a/src/message_port_common.c +++ b/src/message_port_common.c @@ -89,6 +89,12 @@ int write_socket(int fd, *bytes_write += nb; retry_cnt = 0; } + + if (left != 0) { + _LOGE("error fd %d: retry_cnt %d", fd, retry_cnt); + return MESSAGE_PORT_ERROR_IO_ERROR; + } + return MESSAGE_PORT_ERROR_NONE; } @@ -153,6 +159,12 @@ int read_socket(int fd, *bytes_read += nb; retry_cnt = 0; } + + if (left != 0) { + _LOGE("error fd %d: retry_cnt %d", fd, retry_cnt); + return MESSAGE_PORT_ERROR_IO_ERROR; + } + return MESSAGE_PORT_ERROR_NONE; } diff --git a/src/message_port_remote.c b/src/message_port_remote.c index c1e3334..10c23a5 100755 --- a/src/message_port_remote.c +++ b/src/message_port_remote.c @@ -276,6 +276,7 @@ static gboolean __socket_request_handler(GIOChannel *gio, message_port_local_port_info_s *local_port_info; bundle *kb = NULL; GError *error = NULL; + bool ret = TRUE; mi = (message_port_callback_info_s *)data; if (mi == NULL) { @@ -315,15 +316,23 @@ static gboolean __socket_request_handler(GIOChannel *gio, } kb = bundle_decode(pkt->data, pkt->data_len); + if (!kb) { + _LOGE("Invalid argument : message"); + __callback_info_free_by_info(mi); + ret = FALSE; + goto out; + } + if (pkt->is_bidirection) local_port_info->callback(mi->local_id, mi->remote_app_id, pkt->remote_port_name, pkt->is_trusted, kb, local_port_info->user_data); - else local_port_info->callback(mi->local_id, mi->remote_app_id, NULL, pkt->is_trusted, kb, local_port_info->user_data); bundle_free(kb); + +out: if (pkt) { if (pkt->remote_port_name) free(pkt->remote_port_name); @@ -332,7 +341,7 @@ static gboolean __socket_request_handler(GIOChannel *gio, free(pkt); } - return TRUE; + return ret; } static bool __receive_message(GVariant *parameters, GDBusMethodInvocation *invocation)