]> git.alsa-project.org Git - alsa-lib.git/commitdiff
topology: Check address and length before string copy
authorMengdong Lin <mengdong.lin@linux.intel.com>
Wed, 20 Jul 2016 01:53:12 +0000 (09:53 +0800)
committerTakashi Iwai <tiwai@suse.de>
Wed, 20 Jul 2016 05:46:45 +0000 (07:46 +0200)
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>
Reviewed-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/topology/tplg_local.h

index 4d79aa7b45194e5127a1979d944c5e0ae3ca39c4..cfde4cc5a4196aa10d7b83f6be80650fa215c188 100644 (file)
@@ -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;
 }