cx18: introduce a helper function to void array overrun
Subsystems (2)
PATCH 1/1 cx18: introduce a helper function to void array overrun
cx18_i2c_register() is called in cx18_init_subdevs() with index greater than length of hw_bus array, that will cause array overrun, introduce a helper cx18_get_max_bus_num() to void it.
--- drivers/media/pci/cx18/cx18-driver.c | 2 +- drivers/media/pci/cx18/cx18-i2c.c | 5 +++++ drivers/media/pci/cx18/cx18-i2c.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-)
drivers/media/pci/cx18/cx18-driver.c +1 -1
@@ -856,7 +856,7 @@ static void cx18_init_subdevs(struct cx18 *cx)u32 device;int i; -for (i =0 , device =1 ; i <32 ; i++, device <<=1 ) { +for (i =0 , device =1 ; i <cx18_get_max_bus_num (); i++, device <<=1 ) {if (!(device & hw))continue ;
drivers/media/pci/cx18/cx18-i2c.c +5 -0
@@ -108,6 +108,11 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, -1 : 0; } +int cx18_get_max_bus_num () +{ +return sizeof (hw_bus); +} +int cx18_i2c_register (struct cx18 *cx,unsigned idx) {struct v4l2_subdev *sd;
drivers/media/pci/cx18/cx18-i2c.h +1 -0
@@ -21,6 +21,7 @@* 02111-1307 USA */ +int cx18_get_max_bus_num ();int cx18_i2c_register (struct cx18 *cx,unsigned idx);struct v4l2_subdev *cx18_find_hw (struct cx18 *cx,u32 hw);
Signature · 1 line
1.8.3.4 (Apple Git-47)
Hi Ethan,
Quoted 3 lines · Ethan Zhao
cx18_i2c_register()is called incx18_init_subdevs()with index greater than length ofhw_busarray, that will cause array overrun, introduce a helpercx18_get_max_bus_num()to void it.
s/void/avoid/
Quoted 26 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/media/pci/cx18/cx18-driver.c | 2 +- drivers/media/pci/cx18/cx18-i2c.c | 5 +++++ drivers/media/pci/cx18/cx18-i2c.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-)drivers/media/pci/cx18/cx18-driver.c +1
-1@@ -856,7 +856,7 @@ static void cx18_init_subdevs(struct cx18 *cx)u32 device;int i; -for (i =0 , device =1 ; i <32 ; i++, device <<=1 ) { +for (i =0 , device =1 ; i <cx18_get_max_bus_num (); i++, device <<=1 ) {if (!(device & hw))continue ;drivers/media/pci/cx18/cx18-i2c.c +0
-0
drivers/media/pci/cx18/cx18-i2c.c static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, · line 111
Quoted 4 lines
drivers/media/pci/cx18/cx18-i2c.c +1
-0@@ -108,6 +108,11 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, -1 : 0; } +int cx18_get_max_bus_num ()
This should be "int cx18_get_max_bus_num(void)" since we are using C and not C++.
drivers/media/pci/cx18/cx18-i2c.c static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, · line 113
Quoted 2 lines
drivers/media/pci/cx18/cx18-i2c.c +2
-0+{ +return sizeof (hw_bus);
I'd rather see
return ARRAY_SIZE(hw_bus);
Thanks.
Signature · 1 line
Dmitry
Quoted 8 lines · Dmitry Torokhov
Hi Ethan,
Quoted 3 lines · Ethan Zhao
cx18_i2c_register()is called incx18_init_subdevs()with index greater than length ofhw_busarray, that will cause array overrun, introduce a helpercx18_get_max_bus_num()to void it.s/void/avoid/
Oops, typo.
Quoted 30 lines
Quoted 30 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/media/pci/cx18/cx18-driver.c | 2 +- drivers/media/pci/cx18/cx18-i2c.c | 5 +++++ drivers/media/pci/cx18/cx18-i2c.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-)drivers/media/pci/cx18/cx18-driver.c +1
-1@@ -856,7 +856,7 @@ static void cx18_init_subdevs(struct cx18 *cx)u32 device;int i; -for (i =0 , device =1 ; i <32 ; i++, device <<=1 ) { +for (i =0 , device =1 ; i <cx18_get_max_bus_num (); i++, device <<=1 ) {if (!(device & hw))continue ;drivers/media/pci/cx18/cx18-i2c.c +0
-0@@ -108,6 +108,11 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, -1 : 0; }
Quoted 4 lines
drivers/media/pci/cx18/cx18-i2c.c static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, · line 111
Quoted 1 line
drivers/media/pci/cx18/cx18-i2c.c +1
-0+int cx18_get_max_bus_num ()This should be "int
cx18_get_max_bus_num(void)" since we are using C and not C++.
agree, no parameter function, f(void) much clearer than any parameters function f() in C.
Quoted 7 lines
drivers/media/pci/cx18/cx18-i2c.c static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, · line 113
Quoted 3 lines
drivers/media/pci/cx18/cx18-i2c.c +2
-0+{ +return sizeof (hw_bus);I'd rather see
return ARRAY_SIZE(hw_bus);
Yes, looks better ! will send v2, thanks.
Quoted 5 lines
Thanks.
--
Dmitry