From: Joe Perches <joe@perches.com>
To: Salah Triki <salah.triki@gmail.com>,
bp@alien8.de, mchehab@kernel.org, tony.luck@intel.com,
james.morse@arm.com, rric@kernel.org
Cc: linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RESEND] edac: replace sprintf() by scnprintf()
Date: Sat, 10 Jul 2021 09:58:46 -0700 [thread overview]
Message-ID: <d95595021eb8da542960fff9b40dc7c308661c9e.camel@perches.com> (raw)
In-Reply-To: <20210710163505.GA689509@pc>
On Sat, 2021-07-10 at 17:35 +0100, Salah Triki wrote:
> Replace sprintf() by scnprintf() in order to avoid buffer overflows.
While of course safe, this is not strictly necessary as the
maximum length of any edac_layer_name is 8 bytes.
drivers/edac/edac_mc.c:const char *edac_layer_name[] = {
drivers/edac/edac_mc.c- [EDAC_MC_LAYER_BRANCH] = "branch",
drivers/edac/edac_mc.c- [EDAC_MC_LAYER_CHANNEL] = "channel",
drivers/edac/edac_mc.c- [EDAC_MC_LAYER_SLOT] = "slot",
drivers/edac/edac_mc.c- [EDAC_MC_LAYER_CHIP_SELECT] = "csrow",
drivers/edac/edac_mc.c- [EDAC_MC_LAYER_ALL_MEM] = "memory",
drivers/edac/edac_mc.c-};
And name is:
char name[80];
I suppose name[80] could be changed to name[32] or so
at the same time to reduce stack usage.
Maybe name should be moved into the loop too.
---
drivers/edac/debugfs.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/edac/debugfs.c b/drivers/edac/debugfs.c
index 4804332d99465..a41071f2ad428 100644
--- a/drivers/edac/debugfs.c
+++ b/drivers/edac/debugfs.c
@@ -55,14 +55,15 @@ void edac_debugfs_exit(void)
void edac_create_debugfs_nodes(struct mem_ctl_info *mci)
{
struct dentry *parent;
- char name[80];
int i;
parent = debugfs_create_dir(mci->dev.kobj.name, edac_debugfs);
for (i = 0; i < mci->n_layers; i++) {
- sprintf(name, "fake_inject_%s",
- edac_layer_name[mci->layers[i].type]);
+ char name[32];
+
+ scnprintf(name, sizeof(name), "fake_inject_%s",
+ edac_layer_name[mci->layers[i].type]);
debugfs_create_u8(name, S_IRUGO | S_IWUSR, parent,
&mci->fake_inject_layer[i]);
}
next prev parent reply other threads:[~2021-07-10 16:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-10 16:35 [RESEND] edac: replace sprintf() by scnprintf() Salah Triki
2021-07-10 16:58 ` Joe Perches [this message]
2021-07-12 12:09 ` Salah Triki
2021-07-12 16:30 ` Joe Perches
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=d95595021eb8da542960fff9b40dc7c308661c9e.camel@perches.com \
--to=joe@perches.com \
--cc=bp@alien8.de \
--cc=james.morse@arm.com \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=rric@kernel.org \
--cc=salah.triki@gmail.com \
--cc=tony.luck@intel.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 NNTP newsgroup(s).