⬢ DragonFlyBSD Kernel Audit
DF-4129 / fix.diff
← back to finding ↓ download raw
--- a/sys/dev/sound/midi/sequencer.c
+++ b/sys/dev/sound/midi/sequencer.c
@@ -82,6 +82,9 @@
 #define EV_SZ 8
 #define IEV_SZ 8
 
+/* Max number of MIDI units per sequencer (midis/midi_flags array bound) */
+#define MIDIDEV_MAX 32
+
 /* Lookup modes */
 #define LOOKUP_EXIST	(0)
 #define LOOKUP_OPEN	(1)
@@ -538,9 +541,10 @@
 	MIDIQ_INIT(scp->out_q, buf, EV_SZ * 1024);
 	ret = EINVAL;
 
-	scp->midis = kmalloc(sizeof(kobj_t) * 32, M_TEMP, M_WAITOK | M_ZERO);
-	scp->midi_flags = kmalloc(sizeof(*scp->midi_flags) * 32, M_TEMP,
+	scp->midis = kmalloc(sizeof(kobj_t) * MIDIDEV_MAX, M_TEMP,
 	    M_WAITOK | M_ZERO);
+	scp->midi_flags = kmalloc(sizeof(*scp->midi_flags) * MIDIDEV_MAX,
+	    M_TEMP, M_WAITOK | M_ZERO);
 
 	scp->flags = 0;
 
@@ -769,7 +773,8 @@
 	if (scp->maxunits == 0)
 		SEQ_DEBUG(2, kprintf("seq_open: no midi devices\n"));
 
-	for (i = 0; i < scp->maxunits; i++) {
+	for (i = 0; i < scp->maxunits && scp->midi_number < MIDIDEV_MAX;
+	    i++) {
 		scp->midis[scp->midi_number] =
 		    midimapper_fetch_synth(scp->mapper, scp->mapper_cookie, i);
 		if (scp->midis[scp->midi_number]) {
@@ -2060,7 +2065,7 @@
 static int
 seq_sync(struct seq_softc *scp)
 {
-	int i, rl, sync[16], done;
+	int i, rl, sync[MIDIDEV_MAX], done;
 
 	KKASSERT(lockowned(&scp->seq_lock));