Skip to contentSkip to conversation

scsi: fix upper bounds check of sense key in scsi_sense_key_string()

PATCH Applied Tyrel Datwyler 2 participants 2 messages Aug 12, 2016 – Aug 16, 2016 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 scsi: fix upper bounds check of sense key in scsi_sense_key_string()

Commit 655ee63cf371 added a "Completed" sense string with key 0xF to snstext[], but failed to updated the upper bounds check of the sense key in scsi_sense_key_string().

Fixes 655ee63cf371 ("[SCSI] scsi constants: command, sense key + additional sense strings")

---

Changes since v1:
- Addressed Bart's comments
- Moved opening function brace to match kernel style guidelines
- Changed upperbounds check to use ARRAY_SIZE instead of fixed value

 drivers/scsi/constants.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/constants.c +3 -2
index 83458f7..6dc96c8 100644
@@ -361,8 +361,9 @@ static const char * const snstext[] = {
 
 /* Get sense key string or NULL if not available */
 const char *
-scsi_sense_key_string(unsigned char key) {
-	if (key <= 0xE)
+scsi_sense_key_string(unsigned char key)
+{
+	if (key < ARRAY_SIZE(snstext))
 		return snstext[key];
 	return NULL;
 }
Signature · 1 line
2.7.4
#1 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Tyrel" == Tyrel Datwyler <[email protected]> writes:

Tyrel> Commit 655ee63cf371 added a "Completed" sense string with key 0xF Tyrel> to snstext[], but failed to updated the upper bounds check of the Tyrel> sense key in scsi_sense_key_string().

Applied to 4.8/scsi-fixes.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering