From 7ba2c7cee75c053be6b6246a7e5b093c65cd66b9 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Wed, 26 Aug 2015 13:07:46 -0400 Subject: [PATCH] etekcity: check for return values before using them If action is NULL, that's a problem. If etekcity_button_action_to_raw() returns 0, we should not try to write 0x00 in the profile. The proper command for "none" is 0x06. 0x00 is thus an error. Signed-off-by: Benjamin Tissoires --- src/driver-etekcity.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/driver-etekcity.c b/src/driver-etekcity.c index 71c14af7..2e04684b 100644 --- a/src/driver-etekcity.c +++ b/src/driver-etekcity.c @@ -366,7 +366,8 @@ etekcity_read_button(struct ratbag_button *button) " - button%d: %s (%02x) %s:%d\n", button->index, print_key(data), data, __FILE__, __LINE__); action = etekcity_raw_to_button_action(data); - button->action = *action; + if (action) + button->action = *action; button->type = etekcity_raw_to_button_type(button->index); } @@ -377,12 +378,16 @@ etekcity_write_button(struct ratbag_button *button, struct ratbag_profile *profile = button->profile; struct ratbag_device *device = profile->device; struct etekcity_data *drv_data = ratbag_get_drv_data(device); - uint8_t *data; + uint8_t rc, *data; unsigned index = etekcity_button_to_index(button->index); data = &drv_data->profiles[profile->index][3 + index * 3]; - *data = etekcity_button_action_to_raw(action); + rc = etekcity_button_action_to_raw(action); + if (!rc) + return -EINVAL; + + *data = rc; return 0; }