diff mbox

[v2,3/3] topology: Check address and length before string copy

Message ID 4a022caadf29e0066cfaca1abe7039ac63777921.1468979281.git.mengdong.lin@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

mengdong.lin@linux.intel.com July 20, 2016, 1:53 a.m. UTC
From: Mengdong Lin <mengdong.lin@linux.intel.com>

elem_copy_text() is widely used for string copy in topology. Because some
name fields are not mandatory for users, sometimes the source can be
invalid and we should not do the copy. So we add check here.

Signed-off-by: Mengdong Lin <mengdong.lin@linux.intel.com>
diff mbox

Patch

diff --git a/src/topology/tplg_local.h b/src/topology/tplg_local.h
index 4d79aa7..cfde4cc 100644
--- a/src/topology/tplg_local.h
+++ b/src/topology/tplg_local.h
@@ -253,6 +253,9 @@  struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
 
 static inline void elem_copy_text(char *dest, const char *src, int len)
 {
+	if (!dest || !src || !len)
+		return;
+
 	strncpy(dest, src, len);
 	dest[len - 1] = 0;
 }