From: Cyril Hrubis <chrubis@suse.cz>
To: Hao Zeng <zenghao@kylinos.cn>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v2] fs/doio:Use the snprintf function to prevent buffer overflow
Date: Mon, 24 Apr 2023 11:29:36 +0200 [thread overview]
Message-ID: <ZEZMAPIUD09kgciI@yuki> (raw)
In-Reply-To: <20230423022702.3486141-1-zenghao@kylinos.cn>
Hi!
> Use the snprintf function instead of sprintf in the write_log.c file
>
> Signed-off-by: Hao Zeng <zenghao@kylinos.cn>
> ---
> testcases/kernel/fs/doio/write_log.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/testcases/kernel/fs/doio/write_log.c b/testcases/kernel/fs/doio/write_log.c
> index e8ef9c7cb..44e6fd165 100644
> --- a/testcases/kernel/fs/doio/write_log.c
> +++ b/testcases/kernel/fs/doio/write_log.c
> @@ -141,7 +141,7 @@ int wlog_open(struct wlog_file *wfile, int trunc, int mode)
>
> oflags = O_RDWR;
> if ((wfile->w_rfd = open(wfile->w_file, oflags)) == -1) {
> - sprintf(Wlog_Error_String,
> + snprintf(Wlog_Error_String, sizeof(Wlog_Error_String),
> "Could not open write log - open(%s, %#o) failed: %s\n",
> wfile->w_file, oflags, strerror(errno));
> close(wfile->w_afd);
There is one more sprintf() in the wlong_open() you have missed, can you
please fix that one as well?
Also with new enough GCC I'm still getting warnings about possible
truncation, looking at the Wlog_Error_String size it would make sense to
bump the buffer size to something as 2048.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2023-04-24 9:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-23 2:27 [LTP] [PATCH v2] fs/doio:Use the snprintf function to prevent buffer overflow Hao Zeng
2023-04-24 9:29 ` Cyril Hrubis [this message]
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=ZEZMAPIUD09kgciI@yuki \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
--cc=zenghao@kylinos.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.