]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
zramctl: fix truncation warning
authorSami Kerola <kerolasa@iki.fi>
Thu, 3 May 2018 21:57:58 +0000 (22:57 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 10 May 2018 09:25:05 +0000 (11:25 +0200)
sys-utils/zramctl.c: In function ‘zram_get_sysfs’:
sys-utils/zramctl.c:220:52: warning: ‘%s’ directive output may be truncated
writing up to 4095 bytes into a region of size 27 [-Wformat-truncation=]
     snprintf(z->devname, sizeof(z->devname), "/dev/%s", name);

As an additional good thing zramctl will no longer allocate 4096 bytes from
stack when just 23 bytes is enough.

[kzak@redhat.com: - use macro rather than hardcoded string for the path]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/zramctl.c

index 8da7b2ddb392d6f817ffcabcd2899ab7489eaeb9..bedb0a042e36ece4f9933ca501fa627895749c49 100644 (file)
@@ -215,9 +215,9 @@ static struct sysfs_cxt *zram_get_sysfs(struct zram *z)
                        return NULL;
                if (*z->devname != '/') {
                        /* canonicalize the device name according to /sys */
-                       char name[PATH_MAX];
+                       char name[sizeof(z->devname) - sizeof(_PATH_DEV)];
                        if (sysfs_get_devname(&z->sysfs, name, sizeof(name)))
-                               snprintf(z->devname, sizeof(z->devname), "/dev/%s", name);
+                               snprintf(z->devname, sizeof(z->devname), _PATH_DEV "%s", name);
                }
        }