Skip to contentSkip to conversation

iio: light: apds9306: Fix off by one in apds9306_sampling_freq_get()

PATCH Applied Dan Carpenter 3 participants 3 messages Apr 4, 2024 – Apr 6, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: light: apds9306: Fix off by one in apds9306_sampling_freq_get()

The > comparison needs to be >= to prevent an out of bounds access.

Fixes 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
---
 drivers/iio/light/apds9306.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/apds9306.c +1 -1
index 4d8490602cd7..49fa6b7d5170 100644
@@ -635,7 +635,7 @@ static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val,
 	if (ret)
 		return ret;
 
-	if (repeat_rate_idx > ARRAY_SIZE(apds9306_repeat_rate_freq))
+	if (repeat_rate_idx >= ARRAY_SIZE(apds9306_repeat_rate_freq))
 		return -EINVAL;
 
 	*val = apds9306_repeat_rate_freq[repeat_rate_idx][0];
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Dan Carpenter

The > comparison needs to be >= to prevent an out of bounds access.

Fixes 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
---
  drivers/iio/light/apds9306.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/apds9306.c +0 -0
index 4d8490602cd7..49fa6b7d5170 100644

drivers/iio/light/apds9306.c static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val, · line 639

Quoted 6 lines
drivers/iio/light/apds9306.c +1 -1
@@ -635,7 +635,7 @@ static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val,
  	if (ret)
  		return ret;
 
-	if (repeat_rate_idx > ARRAY_SIZE(apds9306_repeat_rate_freq))
+	if (repeat_rate_idx >= ARRAY_SIZE(apds9306_repeat_rate_freq))
  		return -EINVAL;

Good find.

Regards,
Subhajit Ghosh

Quoted 2 lines
drivers/iio/light/apds9306.c +0 -0
  	*val = apds9306_repeat_rate_freq[repeat_rate_idx][0];
maintainer Applied
#2 lore raw
Quoted 17 lines · On Fri, 5 Apr 2024 17:44:31 +1030 Subhajit Ghosh…
Quoted 16 lines · Dan Carpenter

The > comparison needs to be >= to prevent an out of bounds access.

Fixes 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
---
  drivers/iio/light/apds9306.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/apds9306.c +0 -0
index 4d8490602cd7..49fa6b7d5170 100644
@@ -635,7 +635,7 @@ static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val,
  	if (ret)
  		return ret;
 
Quoted 7 lines

drivers/iio/light/apds9306.c static int apds9306_sampling_freq_get(struct apds9306_data *data, int *val, · line 639

Quoted 3 lines
drivers/iio/light/apds9306.c +1 -1
-	if (repeat_rate_idx > ARRAY_SIZE(apds9306_repeat_rate_freq))
+	if (repeat_rate_idx >= ARRAY_SIZE(apds9306_repeat_rate_freq))
  		return -EINVAL;  

Good find.

Applied to the togreg branch of iio.git (where the fixes patch is currently) and pushed out as testing initially because there is other stuff in there I want 0-day to checkout before I make a mess of linux-next.

Thanks,

Jonathan

Quoted 5 lines

Regards,
Subhajit Ghosh

Quoted 2 lines
drivers/iio/light/apds9306.c +0 -0
  	*val = apds9306_repeat_rate_freq[repeat_rate_idx][0];