From: sanghyeok.oh Date: Thu, 23 Apr 2020 07:42:48 +0000 (+0900) Subject: dbus: Add signature checking before using g_variant_get() X-Git-Tag: accepted/tizen/5.5/unified/20200904.075131~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F94%2F232994%2F1;p=platform%2Fcore%2Fsystem%2Ffeedbackd.git dbus: Add signature checking before using g_variant_get() Change-Id: Ia8115cbaf411d47cb4f098fb83bb90f9a572ecc2 (cherry picked from commit 4723ef823c1d833aa8cca543d95a001df87ae12e) --- diff --git a/src/auto-test/haptic.c b/src/auto-test/haptic.c index bca8159..ea1022d 100644 --- a/src/auto-test/haptic.c +++ b/src/auto-test/haptic.c @@ -93,13 +93,14 @@ static bool haptic_closedevice() return ret; } - if (!dh_get_param_from_var(msg, "(i)", &handle)) { + if (dh_get_param_from_var(msg, "(i)", &handle)) + ret = request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle)); + else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - return ret; - } + g_variant_unref(msg); - return request_haptic_method(METHOD_HAPTIC_CLOSEDEVICE, g_variant_new("(u)", handle)); + return ret; } static bool haptic_vibratemonotone(int duration, int level, int priority) @@ -120,13 +121,14 @@ static bool haptic_vibratemonotone(int duration, int level, int priority) return ret; } - if (!dh_get_param_from_var(msg, "(i)", &handle)) { + if (dh_get_param_from_var(msg, "(i)", &handle)) + ret = request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, duration, level, priority)); + else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - return ret; - } + g_variant_unref(msg); - return request_haptic_method(METHOD_HAPTIC_VIBRATEMONOTONE, g_variant_new("(uiii)", handle, duration, level, priority)); + return ret; } static bool haptic_vibratepattern(char *pattern, int level, int priority) @@ -147,13 +149,14 @@ static bool haptic_vibratepattern(char *pattern, int level, int priority) return ret; } - if (!dh_get_param_from_var(msg, "(i)", &handle)) { + if (dh_get_param_from_var(msg, "(i)", &handle)) + ret = request_haptic_method(METHOD_HAPTIC_VIBRATEEFFECT, g_variant_new("(usii)", handle, pattern, level, priority)); + else _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); - return ret; - } + g_variant_unref(msg); - return request_haptic_method(METHOD_HAPTIC_VIBRATEEFFECT, g_variant_new("(usii)", handle, pattern, level, priority)); + return ret; } static bool haptic_stopdevice() @@ -177,6 +180,7 @@ static bool haptic_stopdevice() if (!dh_get_param_from_var(msg, "(i)", &handle)) { _E("Failed to call dbus method(%s): no message", METHOD_HAPTIC_OPENDEVICE); + g_variant_unref(msg); return ret; } g_variant_unref(msg); @@ -191,6 +195,7 @@ static bool haptic_stopdevice() _E("Failed to call dbus method(%s): no reply", METHOD_HAPTIC_VIBRATEMONOTONE); return ret; } + g_variant_unref(msg); _D("Sleep 300ms."); time.tv_nsec = 300 * NANO_SECOND_MULTIPLIER; diff --git a/src/haptic/haptic.c b/src/haptic/haptic.c index b35703f..f198016 100644 --- a/src/haptic/haptic.c +++ b/src/haptic/haptic.c @@ -1220,7 +1220,10 @@ static void haptic_poweroff_cb(GDBusConnection *conn, int ret, level; struct timespec time = {0,}; - g_variant_get(param, "(i)", &type); + if (!dh_get_param_from_var(param, "(i)", &type)) { + _E("Failed to get params from gvariant. expected:%s, type:%s", "(i)", g_variant_get_type_string(param)); + return; + } if (type != POWER_OFF_DIRECT && type != POWER_OFF_RESTART) return; @@ -1390,7 +1393,13 @@ void haptic_init(void) if (r < 0) _E("Failed to init hdbus interface and method: %d", r); - id_sig_pwr_off_state = subscribe_dbus_signal(NULL, DEVICED_PATH_POWEROFF, DEVICED_INTERFACE_POWEROFF, SIGNAL_POWEROFF_STATE, haptic_poweroff_cb, NULL, NULL); + id_sig_pwr_off_state = subscribe_dbus_signal(NULL, + DEVICED_PATH_POWEROFF, + DEVICED_INTERFACE_POWEROFF, + SIGNAL_POWEROFF_STATE, + haptic_poweroff_cb, + NULL, + NULL); if (id_sig_pwr_off_state <= 0) { _E("Failed to register signal handler: %d", r); return;