From 8fd27bec0c5cb5ade55cf0a9d606aa1dbeeed95f Mon Sep 17 00:00:00 2001 From: Sami Kerola Date: Thu, 3 May 2018 22:57:58 +0100 Subject: zramctl: fix truncation warning 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 Signed-off-by: Karel Zak --- sys-utils/zramctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sys-utils/zramctl.c') diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c index 8da7b2ddb..bedb0a042 100644 --- a/sys-utils/zramctl.c +++ b/sys-utils/zramctl.c @@ -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); } } -- cgit v1.2.3-55-g7522