mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-07 13:30:07 -05:00
control: ctlparse - use type-specific bound on element count
Using a fixed bound of 128 means that too many values may be set for an INTEGER64 type and that any elements past 128 are out of reach for BYTE type controls. Derive the maximum number of elements from the type so that the full range is parsed for all types. Signed-off-by: John Keeping <john@metanate.com> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
7036ea07c8
commit
198eb642bc
1 changed files with 23 additions and 1 deletions
|
|
@ -304,6 +304,25 @@ static int get_ctl_enum_item_index(snd_ctl_t *handle,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static unsigned int get_ctl_type_max_elements(snd_ctl_elem_type_t type)
|
||||||
|
{
|
||||||
|
struct snd_ctl_elem_value value;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case SND_CTL_ELEM_TYPE_BOOLEAN:
|
||||||
|
case SND_CTL_ELEM_TYPE_INTEGER:
|
||||||
|
return ARRAY_SIZE(value.value.integer.value);
|
||||||
|
case SND_CTL_ELEM_TYPE_INTEGER64:
|
||||||
|
return ARRAY_SIZE(value.value.integer64.value);
|
||||||
|
case SND_CTL_ELEM_TYPE_ENUMERATED:
|
||||||
|
return ARRAY_SIZE(value.value.enumerated.item);
|
||||||
|
case SND_CTL_ELEM_TYPE_BYTES:
|
||||||
|
return ARRAY_SIZE(value.value.bytes.data);
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief parse ASCII string as CTL element value
|
* \brief parse ASCII string as CTL element value
|
||||||
* \param handle CTL handle
|
* \param handle CTL handle
|
||||||
|
|
@ -331,8 +350,11 @@ int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
|
||||||
type = snd_ctl_elem_info_get_type(info);
|
type = snd_ctl_elem_info_get_type(info);
|
||||||
count = snd_ctl_elem_info_get_count(info);
|
count = snd_ctl_elem_info_get_count(info);
|
||||||
snd_ctl_elem_value_set_id(dst, &myid);
|
snd_ctl_elem_value_set_id(dst, &myid);
|
||||||
|
|
||||||
|
if (count > get_ctl_type_max_elements(type))
|
||||||
|
count = get_ctl_type_max_elements(type);
|
||||||
|
|
||||||
for (idx = 0; idx < count && idx < 128 && ptr && *ptr; idx++) {
|
for (idx = 0; idx < count && ptr && *ptr; idx++) {
|
||||||
if (*ptr == ',')
|
if (*ptr == ',')
|
||||||
goto skip;
|
goto skip;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue