From df803e1389716bcdf11932fff47d7f1fc198bc8a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Oct 2014 18:07:21 +0200 Subject: ALSA: control: Warn if too long string is passed to snd_ctl_enum_info() This allows us to catch the bugs in drivers easily. Signed-off-by: Takashi Iwai --- sound/core/control.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sound/core') diff --git a/sound/core/control.c b/sound/core/control.c index b9611344ff9e..f95df84437e1 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -1747,6 +1747,9 @@ int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels, info->value.enumerated.items = items; if (info->value.enumerated.item >= items) info->value.enumerated.item = items - 1; + WARN(strlen(names[info->value.enumerated.item]) >= sizeof(info->value.enumerated.name), + "ALSA: too long item name '%s'\n", + names[info->value.enumerated.item]); strlcpy(info->value.enumerated.name, names[info->value.enumerated.item], sizeof(info->value.enumerated.name)); -- cgit v1.2.3 From a7e6fb99150ebb2852ebd0e7bad9ce37cc9a79dd Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Mon, 20 Oct 2014 18:08:50 +0200 Subject: ALSA: control: Allow to pass items zero to snd_ctl_enum_info() Although this is weird, some drivers want to allow empty control elements intentionally, e.g. the number of items may change depending on the firmware status. Let the function simply returning in such a case. Signed-off-by: Takashi Iwai --- sound/core/control.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sound/core') diff --git a/sound/core/control.c b/sound/core/control.c index f95df84437e1..5c35bbaf881e 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -1745,6 +1745,8 @@ int snd_ctl_enum_info(struct snd_ctl_elem_info *info, unsigned int channels, info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; info->count = channels; info->value.enumerated.items = items; + if (!items) + return 0; if (info->value.enumerated.item >= items) info->value.enumerated.item = items - 1; WARN(strlen(names[info->value.enumerated.item]) >= sizeof(info->value.enumerated.name), -- cgit v1.2.3