lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20231008072423.556591-1-suhui@nfschina.com>
Date:   Sun,  8 Oct 2023 15:24:24 +0800
From:   Su Hui <suhui@...china.com>
To:     ccaulfie@...hat.com, teigland@...hat.com
Cc:     Su Hui <suhui@...china.com>, gfs2@...ts.linux.dev,
        linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org
Subject: [PATCH] fs: dlm: silence truncated string warning

Using gcc and W=1 option, there are some warning like these:

fs/dlm/debug_fs.c: In function ‘dlm_create_debug_file’:
fs/dlm/debug_fs.c:1020:51: error: ‘snprintf’ output may be truncated before
the last format character [-Werror=format-truncation=]
 1020 |  snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name);
      |                                                   ^
fs/dlm/debug_fs.c:1020:2: note: 'snprintf' output between 9 and 73 bytes
into a destination of size 72
 1020 |  snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fs/dlm/debug_fs.c:1031:43: error: '_queued_asts' directive output may be
truncated writing 12 bytes into a region of size between 8 and 72
[-Werror=format-truncation=]
 1031 |  snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_queued_asts",
		  ls->ls_name);
      |                                           ^~~~~~~~~~~~

The length of 'ls->ls_name' is 'DLM_LOCKSPACE_LEN + 1'. So string
"%s_waiters" can up to 'DLM_LOCKSPACE_LEN + 9' and string
"%s_queued_asts" can up to 'DLM_LOCKSPACE_LEN + 13'.

Signed-off-by: Su Hui <suhui@...china.com>
---
 fs/dlm/debug_fs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index 5aabcb6f0f15..d0b34b9fbdaf 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -973,7 +973,7 @@ void dlm_delete_debug_comms_file(void *ctx)
 
 void dlm_create_debug_file(struct dlm_ls *ls)
 {
-	char name[DLM_LOCKSPACE_LEN + 8];
+	char name[DLM_LOCKSPACE_LEN + 13];
 
 	/* format 1 */
 
@@ -1017,7 +1017,7 @@ void dlm_create_debug_file(struct dlm_ls *ls)
 						       &format4_fops);
 
 	memset(name, 0, sizeof(name));
-	snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_waiters", ls->ls_name);
+	snprintf(name, DLM_LOCKSPACE_LEN + 9, "%s_waiters", ls->ls_name);
 
 	ls->ls_debug_waiters_dentry = debugfs_create_file(name,
 							  0644,
@@ -1028,7 +1028,7 @@ void dlm_create_debug_file(struct dlm_ls *ls)
 	/* format 5 */
 
 	memset(name, 0, sizeof(name));
-	snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_queued_asts", ls->ls_name);
+	snprintf(name, DLM_LOCKSPACE_LEN + 13, "%s_queued_asts", ls->ls_name);
 
 	ls->ls_debug_queued_asts_dentry = debugfs_create_file(name,
 							      0644,
-- 
2.30.2

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ