[PATCH] fs: dlm: silence truncated string warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
---
 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




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux