library: Be more verbose in error messages when invalid signals are received 40/279140/3
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 2 Aug 2022 11:54:59 +0000 (13:54 +0200)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Thu, 4 Aug 2022 22:12:06 +0000 (00:12 +0200)
Change-Id: Ibdf14033919604569182d587f3bdb99c73725ff0

libsessiond/src/lib.c
libsessiond/src/lib.h

index 0fdf290..cab546f 100644 (file)
@@ -420,7 +420,10 @@ static void signal_addremove_common_handler(GDBusConnection *connection,
 
        subsession_event_info event_info = { .event = event };
        g_autofree char *user_id = NULL;
-       maybe_g_variant_get_or_ret_(parameters, "(is)", &event_info.session_uid, &user_id);
+       if (!typechecked_g_variant_get(parameters, "(is)", &event_info.session_uid, &user_id)) {
+               LOGW("Received %s signal with incorrect type. Ignoring", signal_name);
+               return;
+       }
 
        if (error_on_bad_user_id(user_id))
                return;
@@ -470,7 +473,10 @@ static void signal_switch_user_common_handler(GDBusConnection *connection,
        subsession_event_info event_info = { .event = event };
        g_autofree char *prev_user = NULL;
        g_autofree char *next_user = NULL;
-       maybe_g_variant_get_or_ret_(parameters, "(ixss)", &event_info.session_uid, &event_info.switch_user.switch_id, &prev_user, &next_user);
+       if (!typechecked_g_variant_get(parameters, "(ixss)", &event_info.session_uid, &event_info.switch_user.switch_id, &prev_user, &next_user)) {
+               LOGW("Received %s signal with incorrect type. Ignoring", signal_name);
+               return;
+       }
 
        if (error_on_switch_bad_user_id(prev_user) || error_on_switch_bad_user_id(next_user))
                return;
index a7fc619..8466c5d 100644 (file)
@@ -49,12 +49,6 @@ typedef struct {
        if (!g_variant_is_of_type(var, G_VARIANT_TYPE(c_str_) )) { return COMPARATOR_RESULT_DIFFERENT_ ; } \
        g_variant_get(var, c_str_, args)
 
-
-//use if function return void type
-#define maybe_g_variant_get_or_ret_(var, c_str_, args...) \
-       if (!g_variant_is_of_type(var, G_VARIANT_TYPE(c_str_) )) { return; } \
-       g_variant_get(var, c_str_, args)
-
 #define int_not_valid(a, ...) || (a <= 0) __VA_ARGS__
 
 #define session_uid_is_not_valid(a, ...) || (a <= 0) __VA_ARGS__