libmultipath(coverity): make sure readlink result is 0-terminated
authorMartin Wilck <mwilck@suse.com>
Tue, 8 Jan 2019 22:54:01 +0000 (23:54 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Sat, 19 Jan 2019 10:41:38 +0000 (11:41 +0100)
Coverity warned that readlink() results aren't necessarily 0-terminated.

Signed-off-by: Martin Wilck <mwilck@suse.com>
libmultipath/util.c

index 944c632..5b838d5 100644 (file)
@@ -176,6 +176,7 @@ int devt2devname(char *devname, int devname_len, char *devt)
        if (stat("/sys/dev/block", &statbuf) == 0) {
                /* Newer kernels have /sys/dev/block */
                sprintf(block_path,"/sys/dev/block/%u:%u", major, minor);
+               dev[FILE_NAME_SIZE - 1] = '\0';
                if (lstat(block_path, &statbuf) == 0) {
                        if (S_ISLNK(statbuf.st_mode) &&
                            readlink(block_path, dev, FILE_NAME_SIZE-1) > 0) {