From 522c67a2c37cde6c6c69b56c2c403a73fe9b7df3 Mon Sep 17 00:00:00 2001 From: Jan Polensky Date: Thu, 11 Sep 2025 15:06:59 +0200 Subject: [PATCH] dasdinfo: Fix format-overflow warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use snprintf() instead of sprintf() to avoid buffer overflow. Also change the integer type from signed to unsigned. Error: dasdinfo.c: In function 'dinfo_create_devnode': dasdinfo.c:297:52: warning: '%04d' directive writing between 4 and 11 bytes into a region of size 5 [-Wformat-overflow=] 297 | sprintf(filename, "dasdinfo%04d", retry); | ^~~~ Reviewed-by: Jan Höppner Signed-off-by: Jan Polensky Signed-off-by: Jan Höppner --- dasdinfo/dasdinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dasdinfo/dasdinfo.c b/dasdinfo/dasdinfo.c index 41844025..cc84dce0 100644 --- a/dasdinfo/dasdinfo.c +++ b/dasdinfo/dasdinfo.c @@ -283,7 +283,7 @@ static int dinfo_create_devnode(dev_t dev, char **devno) char filename[] = "dasdinfo0000"; mode_t mode; unsigned int path; - int retry; + unsigned int retry; int rc; int fd; @@ -294,7 +294,7 @@ static int dinfo_create_devnode(dev_t dev, char **devno) if (pathname[path] == NULL) continue; for (retry = 0; retry < TEMP_DEV_MAX_RETRIES; retry++) { - sprintf(filename, "dasdinfo%04d", retry); + snprintf(filename, sizeof(filename), "dasdinfo%04d", retry); result = dinfo_make_path(pathname[path], filename); if (result == NULL) return -1;