From: Takashi Iwai Subject: Re: [PATCH] sound: using strlcpy instead of strncpy Date: Thu, 20 Jun 2013 13:15:37 +0200 Message-ID: References: <51C2E19B.1080600@huawei.com> 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 08C5E26527E for ; Thu, 20 Jun 2013 13:14:38 +0200 (CEST) In-Reply-To: <51C2E19B.1080600@huawei.com> 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: Zhao Hongjiang Cc: alsa-devel@alsa-project.org, broonie@kernel.org, lgirdwood@gmail.com, wfp5p@virginia.edu List-Id: alsa-devel@alsa-project.org At Thu, 20 Jun 2013 19:03:55 +0800, Zhao Hongjiang wrote: > > for NUL terminated string, need alway set '\0' in the end. > > Signed-off-by: Zhao Hongjiang > --- > sound/oss/soundcard.c | 2 +- > sound/soc/codecs/88pm860x-codec.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/sound/oss/soundcard.c b/sound/oss/soundcard.c > index e778034..53ac987 100644 > --- a/sound/oss/soundcard.c > +++ b/sound/oss/soundcard.c > @@ -99,7 +99,7 @@ int *load_mixer_volumes(char *name, int *levels, int present) > } > n = num_mixer_volumes++; > > - strncpy(mixer_vols[n].name, name, 32); > + strlcpy(mixer_vols[n].name, name, sizeof(mixer_vols[n].name)); This chunk is a wrong fix. The field doesn't have to be NUL-terminated if it's the max length. thanks, Takashi > > if (present) > mixer_vols[n].num = n; > diff --git a/sound/soc/codecs/88pm860x-codec.c b/sound/soc/codecs/88pm860x-codec.c > index 60159c0..6b2e6b3 100644 > --- a/sound/soc/codecs/88pm860x-codec.c > +++ b/sound/soc/codecs/88pm860x-codec.c > @@ -1447,7 +1447,7 @@ static int pm860x_codec_probe(struct platform_device *pdev) > goto out; > } > pm860x->irq[i] = res->start + chip->irq_base; > - strncpy(pm860x->name[i], res->name, MAX_NAME_LEN); > + strlcpy(pm860x->name[i], res->name, sizeof(pm860x->name[i])); > } > > ret = snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pm860x, > -- > 1.7.1 >