linux/sound/xen
Justin Stitt 44900c3ee4 ALSA: xen-front: refactor deprecated strncpy
`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_ always the case for `strncpy`!

It should be noted that, in this case, the destination buffer has a
length strictly greater than the source string. Moreover, the source
string is NUL-terminated (and so is the destination) which means there
was no real bug happening here. Nonetheless, this patch would get us one
step closer to eliminating the `strncpy` API in the kernel, as its use
is too ambiguous. We need to favor less ambiguous replacements such as:
strscpy, strscpy_pad, strtomem and strtomem_pad (amongst others).

Technically, my patch yields subtly different behavior. The original
implementation with `strncpy` would fill the entire destination buffer
with null bytes [3] while `strscpy` will leave the junk, uninitialized
bytes trailing after the _mandatory_ NUL-termination. So, if somehow
`pcm->name` or `card->driver/shortname/longname` require this
NUL-padding behavior then `strscpy_pad` should be used. My
interpretation, though, is that the aforementioned fields are just fine
as NUL-terminated strings. Please correct my assumptions if needed and
I'll send in a v2.

[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
[3]: https://linux.die.net/man/3/strncpy

Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230727-sound-xen-v1-1-89dd161351f1@google.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2023-07-29 13:53:39 +02:00
..
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile ALSA: xen-front: Use Xen common shared buffer implementation 2018-12-18 12:19:37 -05:00
xen_snd_front_alsa.c ALSA: xen-front: refactor deprecated strncpy 2023-07-29 13:53:39 +02:00
xen_snd_front_alsa.h ALSA: xen-front: Implement ALSA virtual sound driver 2018-05-16 12:59:57 +02:00
xen_snd_front_cfg.c ALSA: Convert strlcpy to strscpy when return value is unused 2021-01-08 09:30:05 +01:00
xen_snd_front_cfg.h
xen_snd_front_evtchnl.c xen/sndfront: use xenbus_setup_ring() and xenbus_teardown_ring() 2022-05-19 14:22:08 +02:00
xen_snd_front_evtchnl.h xen/sound: switch xen_snd_front to use INVALID_GRANT_REF 2022-05-19 14:21:46 +02:00
xen_snd_front.c xen: make remove callback of xen driver void returned 2022-12-15 16:06:10 +01:00
xen_snd_front.h ALSA: xen-front: Use Xen common shared buffer implementation 2018-12-18 12:19:37 -05:00