aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2022-08-26 18:01:10 +0300
committerTakashi Iwai <tiwai@suse.de>2022-08-26 17:17:22 +0200
commit5934d9a0383619c14df91af8fd76261dc3de2f5f (patch)
treed535353780bd0183b938b19dd0d62fa454a59e7b
parentALSA: control: Fix an out-of-bounds bug in get_ctl_id_hash() (diff)
downloadlinux-dev-5934d9a0383619c14df91af8fd76261dc3de2f5f.tar.xz
linux-dev-5934d9a0383619c14df91af8fd76261dc3de2f5f.zip
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: 6ab55ec0a938 ("ALSA: control: Fix an out-of-bounds bug in get_ctl_id_hash()") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Link: https://lore.kernel.org/r/YwjgNh/gkG1hH7po@kili Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/core/control.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/sound/core/control.c b/sound/core/control.c
index e8fc4c511e5f..a7271927d875 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -391,7 +391,7 @@ static unsigned long get_ctl_id_hash(const struct snd_ctl_elem_id *id)
h = id->iface;
h = MULTIPLIER * h + id->device;
h = MULTIPLIER * h + id->subdevice;
- for (i = 0; id->name[i] && i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN; i++)
+ for (i = 0; i < SNDRV_CTL_ELEM_ID_NAME_MAXLEN && id->name[i]; i++)
h = MULTIPLIER * h + id->name[i];
h = MULTIPLIER * h + id->index;
h &= LONG_MAX;