ALSA: Warn when control names are truncated
PATCH 1/1 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 <[email protected]>
--- sound/core/control.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
sound/core/control.c +5 -1
@@ -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 :
Signature · 1 line
1.5.6.5
At Wed, 29 Oct 2008 14:14:54 +0000,
sound/core/control.c struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, · line 229
Quoted 4 lines · Mark Brown
sound/core/control.c +2
-1-if (ncontrol->name) +if (ncontrol->name) { +if (strlen (ncontrol->name) >sizeof (kctl.id.name))
This should be '>=' since strlen() doesn't count the terminator.
thanks,
Takashi
Quoted 7 lines · Takashi Iwai
sound/core/control.c struct snd_kcontrol *snd_ctl_new1(const struct snd_kcontrol_new *ncontrol, · line 229
Quoted 3 lines · Mark Brown
sound/core/control.c +2
-1-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).