All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] ALSA: rawmidi: cleanup the get next midi device ioctl
@ 2010-09-08  8:53 ` Dan Carpenter
  0 siblings, 0 replies; 24+ messages in thread
From: Dan Carpenter @ 2010-09-08  8:53 UTC (permalink / raw)
  To: Jaroslav Kysela
  Cc: alsa-devel, Takashi Iwai, Clemens Ladisch, kernel-janitors,
	Kyle McMartin, Ulrich Drepper

I'm doing an audit to find integer overflows and my static checker
complained that in the original code "device + 1" could overflow.  The
overflow is harmless, but it's still worth cleaning up.  The other thing
that I noticed is that if you pass in a device which is higher than
SNDRV_RAWMIDI_DEVICES then it doesn't return an error code but just
tells you that the next device is "device + 1".

I have rewritten it to just return -EINVAL if you pass in a bogus value
that's either too high or too low.  

Signed-off-by: Dan Carpenter <error27@gmail.com>

diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index eb68326..f944180 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -829,8 +829,12 @@ static int snd_rawmidi_control_ioctl(struct snd_card *card,
 		
 		if (get_user(device, (int __user *)argp))
 			return -EFAULT;
+		if (device < 0)
+			return -EINVAL;
+		if (device > SNDRV_RAWMIDI_DEVICES)
+			return -EINVAL;
 		mutex_lock(&register_mutex);
-		device = device < 0 ? 0 : device + 1;
+		device++;
 		while (device < SNDRV_RAWMIDI_DEVICES) {
 			if (snd_rawmidi_search(card, device))
 				break;

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

end of thread, other threads:[~2010-09-09  8:46 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-08  8:53 [patch] ALSA: rawmidi: cleanup the get next midi device ioctl Dan Carpenter
2010-09-08  8:53 ` Dan Carpenter
2010-09-08  9:40 ` Clemens Ladisch
2010-09-08  9:40   ` Clemens Ladisch
2010-09-08 19:36 ` [patch v2] ALSA: rawmidi: fix " Dan Carpenter
2010-09-08 19:36   ` Dan Carpenter
2010-09-08 19:56   ` Takashi Iwai
2010-09-08 19:56     ` Takashi Iwai
2010-09-08 21:29     ` Jaroslav Kysela
2010-09-08 21:29       ` Jaroslav Kysela
2010-09-08 22:11       ` [patch v3] " Dan Carpenter
2010-09-08 22:11         ` Dan Carpenter
2010-09-09  7:07         ` Takashi Iwai
2010-09-09  7:07           ` Takashi Iwai
2010-09-09  8:36           ` Jaroslav Kysela
2010-09-09  8:36             ` Jaroslav Kysela
2010-09-09  7:23         ` walter harms
2010-09-09  7:23           ` walter harms
2010-09-09  6:57       ` [patch v2] " Takashi Iwai
2010-09-09  6:57         ` Takashi Iwai
2010-09-09  7:44   ` Clemens Ladisch
2010-09-09  7:44     ` Clemens Ladisch
2010-09-09  8:46     ` Dan Carpenter
2010-09-09  8:46       ` Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.