]> git.alsa-project.org Git - alsa-utils.git/commitdiff
amixer: expand local storage for item name according to kernel code
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Wed, 8 Apr 2015 16:30:56 +0000 (01:30 +0900)
committerTakashi Iwai <tiwai@suse.de>
Thu, 9 Apr 2015 06:11:05 +0000 (08:11 +0200)
According to kernel code (snd_ctl_elem_init_enum_names() in
sound/core/control.c), the maximum length of item name is 63 characters
(+ 1 terminator = 64 bytes). But current amixer implementation
uses 40 bytes. This causes name truncation and fail to operation.

This commit fixes this bug by expanding the length of local variables.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
amixer/amixer.c

index 36c92eb99bc9e3f0104e3b573c64aba1e6c7cbca..db1849333da3c09d8661dd0d4d7adb6c953230e5 100644 (file)
@@ -812,7 +812,11 @@ static int show_selem(snd_mixer_t *handle, snd_mixer_selem_id_t *id, const char
                if (snd_mixer_selem_is_enumerated(elem)) {
                        int i, items;
                        unsigned int idx;
-                       char itemname[40];
+                       /*
+                        * See snd_ctl_elem_init_enum_names() in
+                        * sound/core/control.c.
+                        */
+                       char itemname[64];
                        items = snd_mixer_selem_get_enum_items(elem);
                        printf("  Items:");
                        for (i = 0; i < items; i++) {
@@ -1255,7 +1259,9 @@ static int get_enum_item_index(snd_mixer_elem_t *elem, char **ptrp)
 {
        char *ptr = *ptrp;
        int items, i, len;
-       char name[40];
+
+       /* See snd_ctl_elem_init_enum_names() in sound/core/control.c. */
+       char name[64];
        
        items = snd_mixer_selem_get_enum_items(elem);
        if (items <= 0)
@@ -1264,6 +1270,7 @@ static int get_enum_item_index(snd_mixer_elem_t *elem, char **ptrp)
        for (i = 0; i < items; i++) {
                if (snd_mixer_selem_get_enum_item_name(elem, i, sizeof(name)-1, name) < 0)
                        continue;
+
                len = strlen(name);
                if (! strncmp(name, ptr, len)) {
                        if (! ptr[len] || ptr[len] == ',' || ptr[len] == '\n') {