util-linux/zramctl-fix-truncation-warning.patch
2019-09-30 11:19:16 -04:00

44 lines
1.5 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 8fd27bec0c5cb5ade55cf0a9d606aa1dbeeed95f Mon Sep 17 00:00:00 2001
From: Sami Kerola <kerolasa@iki.fi>
Date: Thu, 3 May 2018 22:57:58 +0100
Subject: [PATCH 104/686] zramctl: fix truncation warning
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys-utils/zramctl.c b/sys-utils/zramctl.c
index 8da7b2d..bedb0a0 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);
}
}
--
1.8.3.1