diff mbox series

ath5k: fix an off by one check in ath5k_eeprom_read_freq_list()

Message ID Y+D9hPQrHfWBJhXz@kili (mailing list archive)
State Accepted
Commit 4c856ee12df85aabd437c3836ed9f68d94268358
Delegated to: Kalle Valo
Headers show
Series ath5k: fix an off by one check in ath5k_eeprom_read_freq_list() | expand

Commit Message

Dan Carpenter Feb. 6, 2023, 1:15 p.m. UTC
This loop checks that i < max at the start of loop but then it does
i++ which could put it past the end of the array.  It's harmless to
check again and prevent a potential out of bounds.

Fixes: 1048643ea94d ("ath5k: Clean up eeprom parsing and add missing calibration data")
Signed-off-by: Dan Carpenter <error27@gmail.com>
---

 drivers/net/wireless/ath/ath5k/eeprom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Luis Chamberlain Feb. 6, 2023, 2:54 p.m. UTC | #1
On Mon, Feb 06, 2023 at 04:15:48PM +0300, Dan Carpenter wrote:
> This loop checks that i < max at the start of loop but then it does
> i++ which could put it past the end of the array.  It's harmless to
> check again and prevent a potential out of bounds.
> 
> Fixes: 1048643ea94d ("ath5k: Clean up eeprom parsing and add missing calibration data")
> Signed-off-by: Dan Carpenter <error27@gmail.com>

Reviewed-by:  Luis Chamberlain <mcgrof@kernel.org>

  Luis
Luis Chamberlain Feb. 21, 2023, 10:01 p.m. UTC | #2
On Mon, Feb 06, 2023 at 04:15:48PM +0300, Dan Carpenter wrote:
> This loop checks that i < max at the start of loop but then it does
> i++ which could put it past the end of the array.  It's harmless to
> check again and prevent a potential out of bounds.
> 
> Fixes: 1048643ea94d ("ath5k: Clean up eeprom parsing and add missing calibration data")
> Signed-off-by: Dan Carpenter <error27@gmail.com>

Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>

 Luis
Kalle Valo Feb. 22, 2023, 9:56 a.m. UTC | #3
Dan Carpenter <error27@gmail.com> wrote:

> This loop checks that i < max at the start of loop but then it does
> i++ which could put it past the end of the array.  It's harmless to
> check again and prevent a potential out of bounds.
> 
> Fixes: 1048643ea94d ("ath5k: Clean up eeprom parsing and add missing calibration data")
> Signed-off-by: Dan Carpenter <error27@gmail.com>
> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
> Signed-off-by: Kalle Valo <quic_kvalo@quicinc.com>

Patch applied to ath-next branch of ath.git, thanks.

4c856ee12df8 wifi: ath5k: fix an off by one check in ath5k_eeprom_read_freq_list()
diff mbox series

Patch

diff --git a/drivers/net/wireless/ath/ath5k/eeprom.c b/drivers/net/wireless/ath/ath5k/eeprom.c
index d444b3d70ba2..58d3e86f6256 100644
--- a/drivers/net/wireless/ath/ath5k/eeprom.c
+++ b/drivers/net/wireless/ath/ath5k/eeprom.c
@@ -529,7 +529,7 @@  ath5k_eeprom_read_freq_list(struct ath5k_hw *ah, int *offset, int max,
 		ee->ee_n_piers[mode]++;
 
 		freq2 = (val >> 8) & 0xff;
-		if (!freq2)
+		if (!freq2 || i >= max)
 			break;
 
 		pc[i++].freq = ath5k_eeprom_bin2freq(ee,