[alsa-devel] [PATCH] ALSA: Warn when control names are truncated
This is likely to confuse user interfaces since the end of the control name is interpreted (eg, "Volume", "Switch").
Signed-off-by: Mark Brown broonie@opensource.wolfsonmicro.com --- sound/core/control.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/sound/core/control.c b/sound/core/control.c index 6d71f9a..1257ca8 100644 --- a/sound/core/control.c +++ b/sound/core/control.c @@ -225,8 +225,12 @@ struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, kctl.id.iface = ncontrol->iface; kctl.id.device = ncontrol->device; kctl.id.subdevice = ncontrol->subdevice; - if (ncontrol->name) + if (ncontrol->name) { + if (strlen(ncontrol->name) > sizeof(kctl.id.name)) + snd_printk(KERN_WARNING "Control name '%s' truncated\n", + ncontrol->name); strlcpy(kctl.id.name, ncontrol->name, sizeof(kctl.id.name)); + } kctl.id.index = ncontrol->index; kctl.count = ncontrol->count ? ncontrol->count : 1; access = ncontrol->access == 0 ? SNDRV_CTL_ELEM_ACCESS_READWRITE :
On Wed, Oct 29, 2008 at 03:28:50PM +0100, Takashi Iwai wrote:
Mark Brown wrote:
- if (ncontrol->name)
- if (ncontrol->name) {
if (strlen(ncontrol->name) > sizeof(kctl.id.name))
This should be '>=' since strlen() doesn't count the terminator.
Oh, sorry - I'd misread strlcpy() as strncpy() (which would mean that the termination character wasn't needed).
participants (2)
-
Mark Brown
-
Takashi Iwai