Fix socket exception handling 67/148967/2
authorjusung son <jusung07.son@samsung.com>
Mon, 11 Sep 2017 08:26:48 +0000 (17:26 +0900)
committerjusung son <jusung07.son@samsung.com>
Mon, 11 Sep 2017 10:10:22 +0000 (19:10 +0900)
 - Check the unprocessed data

Change-Id: Icaeef2b79ab70b556a2ca4800f6c1d876b0b7a3e
Signed-off-by: jusung son <jusung07.son@samsung.com>
src/message_port_common.c
src/message_port_remote.c

index 4758751..2b9d768 100755 (executable)
@@ -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;
 }
 
index c1e3334..10c23a5 100755 (executable)
@@ -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)