From: Youngjae Cho Date: Fri, 13 May 2022 00:48:25 +0000 (+0900) Subject: device-notifier: prevent index out of bound X-Git-Tag: accepted/tizen/unified/20220526.144053~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d10635a899e9b55ef64a5c4804425d95bd3f2863;p=platform%2Fcore%2Fsystem%2Fdeviced.git device-notifier: prevent index out of bound Change-Id: I5d0ab792bb605f259bc6c7f0a486ecb84d4e3930 Signed-off-by: Youngjae Cho --- diff --git a/src/shared/device-notifier.c b/src/shared/device-notifier.c index 661fae7..48c6716 100644 --- a/src/shared/device-notifier.c +++ b/src/shared/device-notifier.c @@ -54,6 +54,8 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_DELAYED_INIT), NOTIFY_STR(DEVICE_NOTIFIER_LCD), NOTIFY_STR(DEVICE_NOTIFIER_LCD_OFF), + NOTIFY_STR(DEVICE_NOTIFIER_LCD_OFF_COMPLETE), + NOTIFY_STR(DEVICE_NOTIFIER_LCD_AUTOBRT_SENSING), NOTIFY_STR(DEVICE_NOTIFIER_LOWBAT), NOTIFY_STR(DEVICE_NOTIFIER_FULLBAT), NOTIFY_STR(DEVICE_NOTIFIER_POWER_SUPPLY), @@ -61,6 +63,8 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_PRESENT), NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_OVP), NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_CHARGING), + NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_CHARGER_CONNECTED), + NOTIFY_STR(DEVICE_NOTIFIER_BATTERY_CHARGER_DISCONNECTED), NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_AMBIENT_CONDITION), NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_AMBIENT_STATE), NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_LOCK), @@ -72,6 +76,8 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_USB_DEBUG_MODE), NOTIFY_STR(DEVICE_NOTIFIER_USB_TETHERING_MODE), NOTIFY_STR(DEVICE_NOTIFIER_EVENT_HANDLER), + NOTIFY_STR(DEVICE_NOTIFIER_CPU_BOOST_LOWBAT), + NOTIFY_STR(DEVICE_NOTIFIER_CPU_BOOST_POWEROFF), NOTIFY_STR(DEVICE_NOTIFIER_PMQOS), NOTIFY_STR(DEVICE_NOTIFIER_PMQOS_ULTRAPOWERSAVING), NOTIFY_STR(DEVICE_NOTIFIER_PMQOS_POWERSAVING), @@ -83,6 +89,17 @@ static const char *device_notifier_type_str[DEVICE_NOTIFIER_MAX] = { NOTIFY_STR(DEVICE_NOTIFIER_BEZEL_WAKEUP), NOTIFY_STR(DEVICE_NOTIFIER_DISPLAY_BRIGHTNESS), NOTIFY_STR(DEVICE_NOTIFIER_ULTRAPOWERSAVING), + NOTIFY_STR(DEVICE_NOTIFIER_EXTCON_COUNT), + NOTIFY_STR(DEVICE_NOTIFIER_KEY_PRESS), + NOTIFY_STR(DEVICE_NOTIFIER_KEY_RELEASE), + + /* action triggered by input event */ + NOTIFY_STR(DEVICE_NOTIFIER_INPUT_TRIGGER_POWEROFF), + NOTIFY_STR(DEVICE_NOTIFIER_INPUT_BROADCAST_SIGNAL), + + /* Purpose of calling methods of different modules + * Use prefix DEVICE_NOTIFIER_REQUEST */ + NOTIFY_STR(DEVICE_NOTIFIER_REQUEST_TRANSITION_STATE), }; static gint compare_priority(gconstpointer a, gconstpointer b) @@ -96,6 +113,9 @@ int __register_notifier(enum device_notifier_type type, notify_cb func, int prio GList *n; struct device_notifier *notifier; + if (type < DEVICE_NOTIFIER_MIN || type >= DEVICE_NOTIFIER_MAX) + return -EINVAL; + _I("%s, %p by %s", device_notifier_type_str[type], func, caller); if (!func) { @@ -131,6 +151,9 @@ int __register_notifier_udata(enum device_notifier_type type, struct device_notifier *notifier; static int id = 1; + if (type < DEVICE_NOTIFIER_MIN || type >= DEVICE_NOTIFIER_MAX) + return -EINVAL; + _I("%s, %p by %s", device_notifier_type_str[type], func_udata, caller); if (!func_udata) { @@ -163,6 +186,9 @@ int __unregister_notifier(enum device_notifier_type type, notify_cb func, const GList *n; struct device_notifier *notifier; + if (type < DEVICE_NOTIFIER_MIN || type >= DEVICE_NOTIFIER_MAX) + return -EINVAL; + if (!func) { _E("invalid func address of %s! by %s", device_notifier_type_str[type], caller); return -EINVAL; diff --git a/src/shared/device-notifier.h b/src/shared/device-notifier.h index 3a24a2f..1635b3d 100644 --- a/src/shared/device-notifier.h +++ b/src/shared/device-notifier.h @@ -21,7 +21,8 @@ #define __DEVICE_NOTIFIER_H__ enum device_notifier_type { - DEVICE_NOTIFIER_DAEMON_RESTARTED, + DEVICE_NOTIFIER_MIN, + DEVICE_NOTIFIER_DAEMON_RESTARTED = DEVICE_NOTIFIER_MIN, DEVICE_NOTIFIER_DELAYED_INIT, DEVICE_NOTIFIER_LCD, DEVICE_NOTIFIER_LCD_OFF,