Skip to contentSkip to conversation

sound: using strlcpy instead of strncpy

PATCH In review Zhao Hongjiang 2 participants 2 messages Jun 20, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sound: using strlcpy instead of strncpy

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

---
 sound/oss/soundcard.c             |    2 +-
 sound/soc/codecs/88pm860x-codec.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
sound/oss/soundcard.c +1 -1
index e778034..53ac987 100644
@@ -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;
sound/soc/codecs/88pm860x-codec.c +1 -1
index 60159c0..6b2e6b3 100644
@@ -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,
Signature · 1 line
1.7.1
#1 lore raw

At Thu, 20 Jun 2013 19:03:55 +0800,

Quoted 14 lines · Zhao Hongjiang

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

---
 sound/oss/soundcard.c             |    2 +-
 sound/soc/codecs/88pm860x-codec.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
sound/oss/soundcard.c +0 -0
index e778034..53ac987 100644

sound/oss/soundcard.c int *load_mixer_volumes(char *name, int *levels, int present) · line 102

Quoted 5 lines
sound/oss/soundcard.c +1 -1
@@ -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

Quoted 19 lines
sound/oss/soundcard.c +0 -0
 	if (present)
 		mixer_vols[n].num = n;
sound/soc/codecs/88pm860x-codec.c +1 -1
index 60159c0..6b2e6b3 100644
@@ -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,
Signature · 1 line
1.7.1