Skip to content

Commit

Permalink
ASoC: Intel: Skylake: replace deprecated strncpy with strscpy
Browse files Browse the repository at this point in the history
`strncpy` is deprecated for use on NUL-terminated destination strings [1].

A suitable replacement is `strscpy` [2] due to the fact that it
guarantees NUL-termination on its destination buffer argument which is
_not_ the case for `strncpy`!

It was pretty difficult, in this case, to try and figure out whether or
not the destination buffer was zero-initialized. If it is and this
behavior is relied on then perhaps `strscpy_pad` is the preferred
option here.

Kees was able to help me out and identify the following code snippet
which seems to show that the destination buffer is zero-initialized.

|       skl = devm_kzalloc(&pci->dev, sizeof(*skl), GFP_KERNEL);

With this information, I opted for `strscpy` since padding is seemingly
not required.

[1]: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings
[2]: manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html

Link: KSPP#90
Suggested-by: Kees Cook <[email protected]>
Signed-off-by: Justin Stitt <[email protected]>
  • Loading branch information
JustinStitt authored and intel-lab-lkp committed Jul 27, 2023
1 parent 0b4a9fd commit 400a913
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion sound/soc/intel/skylake/skl-topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -3159,7 +3159,7 @@ static int skl_tplg_fill_str_mfest_tkn(struct device *dev,
return -EINVAL;
}

strncpy(skl->lib_info[ref_count].name,
strscpy(skl->lib_info[ref_count].name,
str_elem->string,
ARRAY_SIZE(skl->lib_info[ref_count].name));
ref_count++;
Expand Down

0 comments on commit 400a913

Please sign in to comment.