]> git.alsa-project.org Git - alsa-lib.git/commitdiff
control: ctlparse - use type-specific bound on element count
authorJohn Keeping <john@metanate.com>
Tue, 16 Jun 2020 18:29:30 +0000 (19:29 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 16 Jun 2020 19:29:20 +0000 (21:29 +0200)
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>
src/control/ctlparse.c

index 1ac31bb9d925ba3bff8c40497d7d6e4f596550b0..ee1e0602cbf796f8ce307df34dc4aa27db0c53ae 100644 (file)
@@ -304,6 +304,25 @@ static int get_ctl_enum_item_index(snd_ctl_t *handle,
        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
  * \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);
        count = snd_ctl_elem_info_get_count(info);
        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 == ',')
                        goto skip;
                switch (type) {