From f30ea0dc4dbe63057200bddb2573ae3a6be416ad Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Wed, 2 Sep 2015 21:40:05 +0200 Subject: [PATCH 1/3] RATBAG_BUTTON_TYPE_UNKNOWN is not a ratbag_button_action Just return a NULL. RATBAG_BUTTON_TYPE_UNKNOWN is 0 so no functional change intendend here. --- src/hidpp-generic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hidpp-generic.c b/src/hidpp-generic.c index 9862c5c3..15ee135c 100644 --- a/src/hidpp-generic.c +++ b/src/hidpp-generic.c @@ -146,7 +146,7 @@ hidpp20_1b04_get_logical_mapping(uint16_t value) return &map->action; } - return RATBAG_BUTTON_TYPE_UNKNOWN; + return NULL; } uint16_t From 5f2d538e10fc78f24d748f7a1f3721e0eaada32a Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Wed, 2 Sep 2015 21:47:23 +0200 Subject: [PATCH 2/3] Avoid overflow when reading dpi list LONG_MESSAGE_LENGTH is the length of the full message so we should take the first parts of the union into account. --- src/hidpp20.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hidpp20.c b/src/hidpp20.c index d554e061..4779e5a8 100644 --- a/src/hidpp20.c +++ b/src/hidpp20.c @@ -779,7 +779,7 @@ hidpp20_adjustable_dpi_get_dpi_list(struct ratbag_device *device, sensor->dpi_min = 0xffff; sensor->index = msg.msg.parameters[0]; - while (i < LONG_MESSAGE_LENGTH - 1 && + while (i < LONG_MESSAGE_LENGTH - 4U && hidpp20_get_unaligned_u16(&msg.msg.parameters[i]) != 0) { uint16_t value = hidpp20_get_unaligned_u16(&msg.msg.parameters[i]); From 9011876d1b261094fdeb3a1f1fec136f0d8976a8 Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Wed, 2 Sep 2015 22:03:05 +0200 Subject: [PATCH 3/3] drop inconsistent null check We do not check dev for null in any of the other functions. If it was actually null then we would also already have got a null pointer dereference earlier in the function. --- src/hidpp10.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/hidpp10.c b/src/hidpp10.c index 950b1f5e..c3cacd7c 100644 --- a/src/hidpp10.c +++ b/src/hidpp10.c @@ -294,8 +294,7 @@ hidpp10_set_individual_feature(struct hidpp10_device *dev, log_raw(dev->ratbag_device->ratbag, "Setting individual features\n"); - if (dev) - mode.msg.device_idx = dev->index; + mode.msg.device_idx = dev->index; mode.msg.parameters[0] = feature_bit_r0; mode.msg.parameters[1] = feature_bit_r2;