From: Takashi Iwai Subject: Re: [PATCH 2/2] ALSA: snd-usb: use strncpy() in mixer_quirks.c Date: Sun, 19 Oct 2014 11:38:58 +0200 Message-ID: References: <1413702686-8751-1-git-send-email-daniel@zonque.org> <1413702686-8751-2-git-send-email-daniel@zonque.org> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id 162ED260498 for ; Sun, 19 Oct 2014 11:38:59 +0200 (CEST) In-Reply-To: <1413702686-8751-2-git-send-email-daniel@zonque.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Daniel Mack Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org 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 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. thanks, Takashi > --- > sound/usb/mixer_quirks.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c > index f119a41..f406305 100644 > --- a/sound/usb/mixer_quirks.c > +++ b/sound/usb/mixer_quirks.c > @@ -446,8 +446,9 @@ static int snd_emu0204_ch_switch_info(struct snd_kcontrol *kcontrol, > 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]); > + strncpy(uinfo->value.enumerated.name, > + texts[uinfo->value.enumerated.item], > + sizeof(uinfo->value.enumerated.name) - 1); > > return 0; > } > -- > 2.1.0 >