diff mbox series

[next] ALSA: rawmidi: fix incorrect array bounds check on clock_names

Message ID 20210519105424.55221-1-colin.king@canonical.com (mailing list archive)
State New, archived
Headers show
Series [next] ALSA: rawmidi: fix incorrect array bounds check on clock_names | expand

Commit Message

Colin King May 19, 2021, 10:54 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

The array bounds check on clock_names is currently checking the size
of the entire array rather than the number of elements in the array
leading to a potential array bounds read error. Fix this by using
the ARRAY_SIZE macro instead of sizeof.

Addresses-Coverity: ("Out-of-bounds read")
Fixes: 08fdced60ca0 ("ALSA: rawmidi: Add framing mode")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 sound/core/rawmidi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Takashi Iwai May 19, 2021, 2:20 p.m. UTC | #1
On Wed, 19 May 2021 12:54:24 +0200,
Colin King wrote:
> 
> From: Colin Ian King <colin.king@canonical.com>
> 
> The array bounds check on clock_names is currently checking the size
> of the entire array rather than the number of elements in the array
> leading to a potential array bounds read error. Fix this by using
> the ARRAY_SIZE macro instead of sizeof.
> 
> Addresses-Coverity: ("Out-of-bounds read")
> Fixes: 08fdced60ca0 ("ALSA: rawmidi: Add framing mode")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Thanks, applied.


Takashi
diff mbox series

Patch

diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 4a6534db77d6..6c0a4a67ad2e 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -1679,7 +1679,7 @@  static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry,
 					    buffer_size, avail, xruns);
 				if (substream->framing == SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP) {
 					clock_type = substream->clock_type >> SNDRV_RAWMIDI_MODE_CLOCK_SHIFT;
-					if (!snd_BUG_ON(clock_type >= sizeof(clock_names)))
+					if (!snd_BUG_ON(clock_type >= ARRAY_SIZE(clock_names)))
 						snd_iprintf(buffer,
 							    "  Framing      : tstamp\n"
 							    "  Clock type   : %s\n",