Skip to contentSkip to conversation

drivers/staging/speakup: avoid out-of-range access

PATCH Samuel Thibault 2 participants 3 messages Jan 5, 2013 – Jan 7, 2013 1 message not in the archive Staging

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Indeed. The same happens in synth_add, so Greg please use this instead:

Check that array index is in-bounds before accessing the synths[] array.

---
 drivers/staging/speakup/synth.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/speakup/synth.c +2 -2
index df95337..b91d22b 100644
@@ -342,7 +342,7 @@ int synth_init(char *synth_name)
 
 	mutex_lock(&spk_mutex);
 	/* First, check if we already have it loaded. */
-	for (i = 0; synths[i] != NULL && i < MAXSYNTHS; i++)
+	for (i = 0; i < MAXSYNTHS && synths[i] != NULL; i++)
 		if (strcmp(synths[i]->name, synth_name) == 0)
 			synth = synths[i];
 
@@ -423,7 +423,7 @@ int synth_add(struct spk_synth *in_synth
 	int i;
 	int status = 0;
 	mutex_lock(&spk_mutex);
-	for (i = 0; synths[i] != NULL && i < MAXSYNTHS; i++)
+	for (i = 0; i < MAXSYNTHS && synths[i] != NULL; i++)
 		/* synth_remove() is responsible for rotating the array down */
 		if (in_synth == synths[i]) {
 			mutex_unlock(&spk_mutex);
maintainer
#2 lore raw
Quoted 7 lines · Samuel Thibault

Indeed. The same happens in synth_add, so Greg please use this instead:

Check that array index is in-bounds before accessing the synths[] array.

Wait, Nickolai wrote the first patch, so how could he sign off on your patch? How about sending me an add-on patch on top of the first one which adds the additional check? That way I'll apply both of them and everyone will get the proper credit?

thanks,

greg k-h

#3 lore raw
Quoted 3 lines · Greg KH, le Mon 07 Jan 2013 09:44:53 -0800, a écrit :

Wait, Nickolai wrote the first patch, so how could he sign off on your patch? How about sending me an add-on patch on top of the first one which adds the additional check?

Right, here it is:

Check that array index is in-bounds before accessing the synths[] array.

---
 drivers/staging/speakup/synth.c |    2 +-
 1 file changed, 1 insertions(+), 1 deletions(-)
drivers/staging/speakup/synth.c +1 -1
index df95337..b91d22b 100644
@@ -423,7 +423,7 @@ int synth_add(struct spk_synth *in_synth
 	int i;
 	int status = 0;
 	mutex_lock(&spk_mutex);
-	for (i = 0; synths[i] != NULL && i < MAXSYNTHS; i++)
+	for (i = 0; i < MAXSYNTHS && synths[i] != NULL; i++)
 		/* synth_remove() is responsible for rotating the array down */
 		if (in_synth == synths[i]) {
 			mutex_unlock(&spk_mutex);