kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: control: Re-order bounds checking in get_ctl_id_hash()
@ 2022-08-26 15:01 Dan Carpenter
  2022-08-26 15:17 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-08-26 15:01 UTC (permalink / raw)
  To: Jaroslav Kysela, Zheyu Ma; +Cc: Takashi Iwai, alsa-devel, kernel-janitors

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>
---
 sound/core/control.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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;
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ALSA: control: Re-order bounds checking in get_ctl_id_hash()
  2022-08-26 15:01 [PATCH] ALSA: control: Re-order bounds checking in get_ctl_id_hash() Dan Carpenter
@ 2022-08-26 15:17 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2022-08-26 15:17 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jaroslav Kysela, Zheyu Ma, Takashi Iwai, alsa-devel, kernel-janitors

On Fri, 26 Aug 2022 17:01:10 +0200,
Dan Carpenter wrote:
> 
> 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>

Thanks, applied.


Takashi

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-08-26 15:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26 15:01 [PATCH] ALSA: control: Re-order bounds checking in get_ctl_id_hash() Dan Carpenter
2022-08-26 15:17 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).