All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sound: using strlcpy instead of strncpy
@ 2013-06-20 11:03 Zhao Hongjiang
  2013-06-20 11:15 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Zhao Hongjiang @ 2013-06-20 11:03 UTC (permalink / raw)
  To: perex; +Cc: tiwai, alsa-devel, broonie, lgirdwood, wfp5p

for NUL terminated string, need alway set '\0' in the end.

Signed-off-by: Zhao Hongjiang <zhaohongjiang@huawei.com>
---
 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));
 
 	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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sound: using strlcpy instead of strncpy
  2013-06-20 11:03 [PATCH] sound: using strlcpy instead of strncpy Zhao Hongjiang
@ 2013-06-20 11:15 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2013-06-20 11:15 UTC (permalink / raw)
  To: Zhao Hongjiang; +Cc: alsa-devel, broonie, lgirdwood, wfp5p

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 <zhaohongjiang@huawei.com>
> ---
>  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
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-20 11:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20 11:03 [PATCH] sound: using strlcpy instead of strncpy Zhao Hongjiang
2013-06-20 11:15 ` Takashi Iwai

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.