Skip to content

Commit 5934d9a

Browse files
Dan Carpentertiwai
authored andcommitted
ALSA: control: Re-order bounds checking in get_ctl_id_hash()
These two checks are in the reverse order so it might read one element beyond the end of the array. First check if the "i" is within bounds before using it. Fixes: 6ab55ec ("ALSA: control: Fix an out-of-bounds bug in get_ctl_id_hash()") Signed-off-by: Dan Carpenter <[email protected]> Link: https://lore.kernel.org/r/YwjgNh/gkG1hH7po@kili Signed-off-by: Takashi Iwai <[email protected]>
1 parent 6ab55ec commit 5934d9a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

sound/core/control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static unsigned long get_ctl_id_hash(const struct snd_ctl_elem_id *id)
391391
h = id->iface;
392392
h = MULTIPLIER * h + id->device;
393393
h = MULTIPLIER * h + id->subdevice;
394-
for (i = 0; id->name[i] && i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN; i++)
394+
for (i = 0; i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN && id->name[i]; i++)
395395
h = MULTIPLIER * h + id->name[i];
396396
h = MULTIPLIER * h + id->index;
397397
h &= LONG_MAX;

0 commit comments

Comments
 (0)