hw/gpio/pca9552: fix off-by-one in QOM led index validation
PATCH 1/1 hw/gpio/pca9552: fix off-by-one in QOM led index validation
pca955x_get_led() and pca955x_set_led() accept led indices equal to pin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register past max_reg.
Use the same >= pin_count bounds check as pca9554_set_pin() and the gpio input handler assert in this file.
--- hw/gpio/pca9552.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/gpio/pca9552.c +4 -4
@@ -311,8 +311,8 @@ static void pca955x_get_led(Object *obj, Visitor *v, const char *name,error_setg (errp,"%s: error reading %s" , __func__, name);return ; } -if (led <0 || led > k->pin_count) { -error_setg (errp,"%s invalid led %s" , __func__, name); +if (led <0 || led >= k->pin_count) { +error_setg (errp,"%s: invalid led %s" , __func__, name);return ; }/*
@@ -352,8 +352,8 @@ static void pca955x_set_led(Object *obj, Visitor *v, const char *name,error_setg (errp,"%s: error reading %s" , __func__, name);return ; } -if (led <0 || led > k->pin_count) { -error_setg (errp,"%s invalid led %s" , __func__, name); +if (led <0 || led >= k->pin_count) { +error_setg (errp,"%s: invalid led %s" , __func__, name);return ; }
Signature · 1 line
2.25.1
Glenn,
Thanks,
C.
Quoted 40 lines · yujun
pca955x_get_led()andpca955x_set_led()accept led indices equal topin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register pastmax_reg.Use the same >=
pin_countbounds check aspca9554_set_pin()and the gpio input handler assert in this file.Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")Signed-off-by yujun <[email protected]>--- hw/gpio/pca9552.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/gpio/pca9552.c +4
-4@@ -311,8 +311,8 @@ static void pca955x_get_led(Object *obj, Visitor *v, const char *name,error_setg (errp,"%s: error reading %s" , __func__, name);return ; } -if (led <0 || led > k->pin_count) { -error_setg (errp,"%s invalid led %s" , __func__, name); +if (led <0 || led >= k->pin_count) { +error_setg (errp,"%s: invalid led %s" , __func__, name);return ; }/* @@ -352,8 +352,8 @@ static void pca955x_set_led(Object *obj, Visitor *v, const char *name,error_setg (errp,"%s: error reading %s" , __func__, name);return ; } -if (led <0 || led > k->pin_count) { -error_setg (errp,"%s invalid led %s" , __func__, name); +if (led <0 || led >= k->pin_count) { +error_setg (errp,"%s: invalid led %s" , __func__, name);return ; }
Quoted 11 lines · yujun
pca955x_get_led()andpca955x_set_led()accept led indices equal topin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register pastmax_reg.Use the same >=
pin_countbounds check aspca9554_set_pin()and the gpio input handler assert in this file.Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")Signed-off-by yujun <[email protected]>
thanks
-- PMM
Thanks,
Glenn
Quoted 40 lines · yujun
pca955x_get_led()andpca955x_set_led()accept led indices equal topin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register pastmax_reg.Use the same >=
pin_countbounds check aspca9554_set_pin()and the gpio input handler assert in this file.Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")Signed-off-by yujun <[email protected]>--- hw/gpio/pca9552.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/gpio/pca9552.c +4
-4@@ -311,8 +311,8 @@ static void pca955x_get_led(Object *obj, Visitor *v, const char *name,error_setg (errp,"%s: error reading %s" , __func__, name);return ; } -if (led <0 || led > k->pin_count) { -error_setg (errp,"%s invalid led %s" , __func__, name); +if (led <0 || led >= k->pin_count) { +error_setg (errp,"%s: invalid led %s" , __func__, name);return ; }/* @@ -352,8 +352,8 @@ static void pca955x_set_led(Object *obj, Visitor *v, const char *name,error_setg (errp,"%s: error reading %s" , __func__, name);return ; } -if (led <0 || led > k->pin_count) { -error_setg (errp,"%s invalid led %s" , __func__, name); +if (led <0 || led >= k->pin_count) { +error_setg (errp,"%s: invalid led %s" , __func__, name);return ; }
Philippe Mathieu-Daudé
AppliedQuoted 5 lines · yujun
pca955x_get_led()andpca955x_set_led()accept led indices equal topin_count, but valid indices are 0..pin_count-1. For a 16-pin device, led16 passes the current check and then accesses an LS register pastmax_reg.
Quoted 8 lines
Use the same >=
pin_countbounds check aspca9554_set_pin()and the gpio input handler assert in this file.Fixes a90d8f84674 ("misc/pca9552: Add qom set and get")Signed-off-by yujun <[email protected]>--- hw/gpio/pca9552.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Queued via hw-misc, thanks!
Phil.