fs: dlm: silence truncated string warning
Subsystems (2)
PATCH 1/1 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'.
--- fs/dlm/debug_fs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/dlm/debug_fs.c +3 -3
@@ -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,
Signature · 1 line
2.30.2