From: Takashi Iwai <tiwai@suse.de>
To: Daniel Mack <daniel@zonque.org>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH 2/2] ALSA: snd-usb: use strncpy() in mixer_quirks.c
Date: Mon, 20 Oct 2014 16:40:15 +0200 [thread overview]
Message-ID: <s5h38ails8g.wl-tiwai@suse.de> (raw)
In-Reply-To: <s5ha94stn4d.wl-tiwai@suse.de>
At Sun, 19 Oct 2014 11:38:58 +0200,
Takashi Iwai wrote:
>
> At Sun, 19 Oct 2014 09:11:26 +0200,
> Daniel Mack wrote:
> >
> > Out of principles, use strncpy() in favor of strcpy().
> > That is, however, an insignificant detail here.
> >
> > Signed-off-by: Daniel Mack <daniel@zonque.org>
>
> Well, blindly doing this isn't optimal, IMO.
> First off, strlcpy() is a better one. And, in the code you patched,
> we already know all strings to be passed. That is, if anything is
> over the buffer size, it's a clear bug. This can be caught by static
> analyzers, or put some debug codes (either for build time or compile
> time) instead of silently trimming the string.
BTW, there is already a nice helper function, snd_ctl_enum_info(), for
the safe enum info setup. Then the patch would become even more
reducing, something like below. We can cover many other places in
similar ways.
A further step would be to add a kernel warning when the given string
is too long as an enum item string. Then we can catch the buggy
driver, too. I'll cook up the patch.
Takashi
---
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index f119a41ed9a9..dd4d5bdea423 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -441,15 +441,7 @@ static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol,
"3/4"
};
- uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
- uinfo->count = 1;
- uinfo->value.enumerated.items = 2;
- if (uinfo->value.enumerated.item > 1)
- uinfo->value.enumerated.item = 1;
- strcpy(uinfo->value.enumerated.name,
- texts[uinfo->value.enumerated.item]);
-
- return 0;
+ return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
}
static int snd_emu0204_ch_switch_get(struct snd_kcontrol *kcontrol,
@@ -745,15 +737,7 @@ static int snd_ftu_eff_switch_info(struct snd_kcontrol *kcontrol,
"Echo"
};
- uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
- uinfo->count = 1;
- uinfo->value.enumerated.items = 8;
- if (uinfo->value.enumerated.item > 7)
- uinfo->value.enumerated.item = 7;
- strcpy(uinfo->value.enumerated.name,
- texts[uinfo->value.enumerated.item]);
-
- return 0;
+ return snd_ctl_enum_info(uinfo, 1, ARRAY_SIZE(texts), texts);
}
static int snd_ftu_eff_switch_get(struct snd_kcontrol *kctl,
next prev parent reply other threads:[~2014-10-20 14:40 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-19 7:11 [PATCH 1/2] ALSA: snd-usb: drop unused varible assigments Daniel Mack
2014-10-19 7:11 ` [PATCH 2/2] ALSA: snd-usb: use strncpy() in mixer_quirks.c Daniel Mack
2014-10-19 9:38 ` Takashi Iwai
2014-10-20 14:40 ` Takashi Iwai [this message]
2014-10-20 14:47 ` Daniel Mack
2014-10-19 9:36 ` [PATCH 1/2] ALSA: snd-usb: drop unused varible assigments Takashi Iwai
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=s5h38ails8g.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=daniel@zonque.org \
/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.