Skip to contentSkip to conversation

ASoC: soc-core: Replace use of strncpy() with strlcpy()

PATCH Applied Dimitris Papastamos 2 participants 2 messages Dec 6, 2010

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

PATCH 1/1 ASoC: soc-core: Replace use of strncpy() with strlcpy()

By using strncpy() if the source string does not have a null byte in the first n bytes, then the destination string is not null-terminated. This can be fixed in a two-step process by manually null-terminating the array after the use of strncpy() or by using strlcpy().

---
 sound/soc/soc-core.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
sound/soc/soc-core.c +2 -2
index fd284a7..e586616 100644
@@ -3202,7 +3202,7 @@ static inline char *fmt_single_name(struct device *dev, int *id)
 	if (dev_name(dev) == NULL)
 		return NULL;
 
-	strncpy(name, dev_name(dev), NAME_SIZE);
+	strlcpy(name, dev_name(dev), NAME_SIZE);
 
 	/* are we a "%s.%d" name (platform and SPI components) */
 	found = strstr(name, dev->driver->name);
@@ -3225,7 +3225,7 @@ static inline char *fmt_single_name(struct device *dev, int *id)
 
 			/* sanitize component name for DAI link creation */
 			snprintf(tmp, NAME_SIZE, "%s.%s", dev->driver->name, name);
-			strncpy(name, tmp, NAME_SIZE);
+			strlcpy(name, tmp, NAME_SIZE);
 		} else
 			*id = 0;
 	}
Signature · 1 line
1.7.3.3
Applied
#1 lore raw
Quoted 4 lines · Dimitris Papastamos

By using strncpy() if the source string does not have a null byte in the first n bytes, then the destination string is not null-terminated. This can be fixed in a two-step process by manually null-terminating the array after the use of strncpy() or by using strlcpy().

Applied, thanks.