OSDN Git Service

ALSA: xen: ensure nul-terminated device name
authorArnd Bergmann <arnd@arndb.de>
Mon, 28 May 2018 15:59:57 +0000 (17:59 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 29 May 2018 06:27:54 +0000 (08:27 +0200)
gcc-8 warns that pcm_instance->name is not necessarily terminated correctly
if the input is more than 80 characters long or lacks a termination byte
itself:

In function 'strncpy',
    inlined from 'cfg_device' at sound/xen/xen_snd_front_cfg.c:399:3,
    inlined from 'xen_snd_front_cfg_card' at sound/xen/xen_snd_front_cfg.c:509:9:
include/linux/string.h:254:9: error: '__builtin_strncpy' specified bound 80 equals destination size [-Werror=stringop-truncation]
  return __builtin_strncpy(p, q, size);

Using strlcpy() instead of strncpy() makes this a bit safer.

Fixes: fd3b36045c2c ("ALSA: xen-front: Read sound driver configuration from Xen store")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/xen/xen_snd_front_cfg.c

index 38c7e1e..684b5f1 100644 (file)
@@ -396,7 +396,7 @@ static int cfg_device(struct xen_snd_front_info *front_info,
 
        str = xenbus_read(XBT_NIL, device_path, XENSND_FIELD_DEVICE_NAME, NULL);
        if (!IS_ERR(str)) {
-               strncpy(pcm_instance->name, str, sizeof(pcm_instance->name));
+               strlcpy(pcm_instance->name, str, sizeof(pcm_instance->name));
                kfree(str);
        }