From 80f65ad065472cfb8cdcae4bae4d91d986c18ea0 Mon Sep 17 00:00:00 2001 From: jusung son Date: Mon, 11 Sep 2017 17:26:48 +0900 Subject: [PATCH] Fix socket exception handling - Check the unprocessed data Change-Id: Icaeef2b79ab70b556a2ca4800f6c1d876b0b7a3e Signed-off-by: jusung son --- src/message_port_common.c | 12 ++++++++++++ src/message_port_remote.c | 13 +++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) 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) -- 2.7.4