Skip to content

Commit

Permalink
ALSA: ump: Don't accept an invalid UMP protocol number
Browse files Browse the repository at this point in the history
When a UMP Stream Configuration message is received, the driver tries
to switch the protocol, but there was no sanity check of the protocol,
hence it can pass an invalid value.  Add the check and bail out if a
wrong value is passed.

Fixes: a798076 ("ALSA: ump: Add helper to change MIDI protocol")
Cc: <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
tiwai committed May 29, 2024
1 parent 6d40dbc commit ac0d71e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sound/core/ump.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,17 @@ static void seq_notify_protocol(struct snd_ump_endpoint *ump)
*/
int snd_ump_switch_protocol(struct snd_ump_endpoint *ump, unsigned int protocol)
{
unsigned int type;

protocol &= ump->info.protocol_caps;
if (protocol == ump->info.protocol)
return 0;

type = protocol & SNDRV_UMP_EP_INFO_PROTO_MIDI_MASK;
if (type != SNDRV_UMP_EP_INFO_PROTO_MIDI1 &&
type != SNDRV_UMP_EP_INFO_PROTO_MIDI2)
return 0;

ump->info.protocol = protocol;
ump_dbg(ump, "New protocol = %x (caps = %x)\n",
protocol, ump->info.protocol_caps);
Expand Down

0 comments on commit ac0d71e

Please sign in to comment.