Add exception handling 19/213519/1
authorJusung Son <jusung07.son@samsung.com>
Fri, 6 Sep 2019 06:36:55 +0000 (15:36 +0900)
committerJusung Son <jusung07.son@samsung.com>
Fri, 6 Sep 2019 06:38:36 +0000 (15:38 +0900)
 - If sender validation fails, close the connected socket

Change-Id: Ib844ea608aad74786279a402e294fb207a9f0ef4
Signed-off-by: Jusung Son <jusung07.son@samsung.com>
src/message_port_remote.c [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 5783b66..37c8702
@@ -225,6 +225,8 @@ static int __get_sender_pid(GDBusConnection *conn, const char *sender_name)
                if (err != NULL) {
                        _LOGE("Failed to get pid [%s]", err->message);
                        g_error_free(err);
+               } else {
+                       _LOGE("Failed to get pid");
                }
                goto out;
        }
@@ -802,6 +804,22 @@ static bool __check_sender_validation(GVariant *parameters, const char *sender,
        return true;
 }
 
+static void __close_socket(GDBusMethodInvocation *invocation)
+{
+       GDBusMessage *msg;
+       GUnixFDList *fd_list;
+       int fd_len;
+       int *returned_fds = NULL;
+
+       msg = g_dbus_method_invocation_get_message(invocation);
+       fd_list = g_dbus_message_get_unix_fd_list(msg);
+       if (fd_list != NULL) {
+               returned_fds = g_unix_fd_list_steal_fds(fd_list, &fd_len);
+               if (returned_fds != NULL) {
+                       close(returned_fds[0]);
+               }
+       }
+}
 static void __dbus_method_call_handler(GDBusConnection *conn,
                                const gchar *sender, const gchar *object_path,
                                const gchar *iface_name, const gchar *method_name,
@@ -811,9 +829,13 @@ static void __dbus_method_call_handler(GDBusConnection *conn,
        _LOGI("method_name: %s, sender: %s", method_name, sender);
        gpointer sender_appid = g_hash_table_lookup(__sender_appid_hash, sender);
        if (sender_appid == NULL) {
-               if (!__check_sender_validation(parameters, sender, conn))
+               if (!__check_sender_validation(parameters, sender, conn)) {
+                       _LOGE("Failed to validate");
+                       __close_socket(invocation);
                        goto out;
+               }
        }
+
        if (g_strcmp0(method_name, "send_message") == 0)
                __receive_message(parameters, invocation);
 out: