All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: clemens@ladisch.de, tiwai@suse.de
Cc: alsa-devel@alsa-project.org
Subject: [PATCH 3/5] amixer: expand local storage for item name according to kernel code
Date: Thu,  9 Apr 2015 01:30:56 +0900	[thread overview]
Message-ID: <1428510659-30393-4-git-send-email-o-takashi@sakamocchi.jp> (raw)
In-Reply-To: <1428510659-30393-1-git-send-email-o-takashi@sakamocchi.jp>

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>
---
 amixer/amixer.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/amixer/amixer.c b/amixer/amixer.c
index a3de375..65ebf20 100644
--- a/amixer/amixer.c
+++ b/amixer/amixer.c
@@ -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') {
-- 
2.1.0

  parent reply	other threads:[~2015-04-08 16:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-08 16:30 [PATCH 0/5 alsa-lib] amixer fixes for enumerated elements Takashi Sakamoto
2015-04-08 16:30 ` [PATCH 1/5] amixer: gather local variables in the beginning of functions Takashi Sakamoto
2015-04-09  6:06   ` Takashi Iwai
2015-04-08 16:30 ` [PATCH 2/5] amixer: fix a bug to handle omitted value in parameter for enumerated element Takashi Sakamoto
2015-04-09  6:09   ` Takashi Iwai
2015-04-08 16:30 ` Takashi Sakamoto [this message]
2015-04-09  6:18   ` [PATCH 3/5] amixer: expand local storage for item name according to kernel code Takashi Iwai
2015-04-08 16:30 ` [PATCH 4/5] amixer: arrange validation logic Takashi Sakamoto
2015-04-09  6:17   ` Takashi Iwai
2015-04-08 16:30 ` [PATCH 5/5] amixer: use the same characters for separator Takashi Sakamoto
2015-04-08 16:37 ` [PATCH 0/5 alsa-utils] amixer fixes for enumerated elements Takashi Sakamoto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1428510659-30393-4-git-send-email-o-takashi@sakamocchi.jp \
    --to=o-takashi@sakamocchi.jp \
    --cc=alsa-devel@alsa-project.org \
    --cc=clemens@ladisch.de \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.