Skip to contentSkip to conversation

ALSA: Write outside array bounds

PATCH In review Roel Kluin 4 participants 4 messages Jul 29, 2009 – Jul 30, 2009 Sound

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 ALSA: Write outside array bounds

e->sad[] is declared with size ELD_MAX_SAD (16), but the guard allows the range 0-31

---
Found with Parfait, http://research.sun.com/projects/parfait/

sound/pci/hda/hda_eld.c +1 -1
index fcad5ec..ec04e58 100644
@@ -539,7 +539,7 @@ static void hdmi_write_eld_info(struct snd_info_entry *entry,
 				sname++;
 				n = 10 * n + name[4] - '0';
 			}
-			if (n < 0 || n > 31) /* double the CEA limit */
+			if (n < 0 || n > ELD_MAX_SAD)
 				continue;
 			if (!strcmp(sname, "_coding_type"))
 				e->sad[n].format = val;
#1 lore raw

PATCH v2 1/1 hda: fix out-of-bound hdmi_eld.sad[] write

Quoted 2 lines · Roel Kluin

e->sad[] is declared with size ELD_MAX_SAD (16), but the guard allows the range 0-31

Good catch, thank you, Roel!

Minor fix: '>=' should be used in this line:

Review

Quoted 1 line
(quoted diff) +1 -0
+			if (n < 0 || n > ELD_MAX_SAD)

So I'd suggest this updated patch.

Thanks,
Fengguang
---
hda: fix out-of-bound hdmi_eld.sad[] write

From: Roel Kluin <[email protected]>

e->sad[] is declared with size ELD_MAX_SAD=16, but the guard allows range 0-31.

---
 sound/pci/hda/hda_eld.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/pci/hda/hda_eld.c +2 -2
@@ -508,7 +508,7 @@ static void hdmi_write_eld_info(struct s
 	char name[64];
 	char *sname;
 	long long val;
-	int n;
+	unsigned int n;
 
 	while (!snd_info_get_line(buffer, line, sizeof(line))) {
 		if (sscanf(line, "%s %llx", name, &val) != 2)
@@ -539,7 +539,7 @@ static void hdmi_write_eld_info(struct s
 				sname++;
 				n = 10 * n + name[4] - '0';
 			}
-			if (n < 0 || n > 31) /* double the CEA limit */
+			if (n >= ELD_MAX_SAD)
 				continue;
 			if (!strcmp(sname, "_coding_type"))
 				e->sad[n].format = val;
#2 lore raw

Re: [PATCH v2] hda: fix out-of-bound hdmi_eld.sad[] write

At Wed, 29 Jul 2009 19:31:14 +0800,

Quoted 5 lines · Wu Fengguang
Quoted 2 lines · Roel Kluin

e->sad[] is declared with size ELD_MAX_SAD (16), but the guard allows the range 0-31

Quoted 7 lines

Good catch, thank you, Roel!

Minor fix: '>=' should be used in this line:

Review

Quoted 1 line
(quoted diff) +1 -0
+			if (n < 0 || n > ELD_MAX_SAD)

So I'd suggest this updated patch.

Applied the updated one now. Thanks.

Takashi

Quoted 37 lines

Thanks,
Fengguang
---
hda: fix out-of-bound hdmi_eld.sad[] write

From: Roel Kluin <[email protected]>

e->sad[] is declared with size ELD_MAX_SAD=16, but the guard allows range 0-31.

---
 sound/pci/hda/hda_eld.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sound/pci/hda/hda_eld.c +2 -2
@@ -508,7 +508,7 @@ static void hdmi_write_eld_info(struct s
 	char name[64];
 	char *sname;
 	long long val;
-	int n;
+	unsigned int n;
 
 	while (!snd_info_get_line(buffer, line, sizeof(line))) {
 		if (sscanf(line, "%s %llx", name, &val) != 2)
@@ -539,7 +539,7 @@ static void hdmi_write_eld_info(struct s
 				sname++;
 				n = 10 * n + name[4] - '0';
 			}
-			if (n < 0 || n > 31) /* double the CEA limit */
+			if (n >= ELD_MAX_SAD)
 				continue;
 			if (!strcmp(sname, "_coding_type"))
 				e->sad[n].format = val;