From: Su Hui <suhui@nfschina.com>
To: ccaulfie@redhat.com, teigland@redhat.com
Cc: Su Hui <suhui@nfschina.com>,
gfs2@lists.linux.dev, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [PATCH] fs: dlm: silence truncated string warning
Date: Sun, 8 Oct 2023 15:24:24 +0800 [thread overview]
Message-ID: <20231008072423.556591-1-suhui@nfschina.com> (raw)
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@nfschina.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
reply other threads:[~2023-10-08 7:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231008072423.556591-1-suhui@nfschina.com \
--to=suhui@nfschina.com \
--cc=ccaulfie@redhat.com \
--cc=gfs2@lists.linux.dev \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=teigland@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).