From: Bart Van Assche <Bart.VanAssche@sandisk.com>
To: "mb@lightnvm.io" <mb@lightnvm.io>, "jg@lightnvm.io" <jg@lightnvm.io>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>,
"javier@cnexlabs.com" <javier@cnexlabs.com>
Subject: Re: [PATCH 1/3] lightnvm: convert sprintf into snprintf
Date: Mon, 10 Apr 2017 18:56:06 +0000 [thread overview]
Message-ID: <1491850565.4199.19.camel@sandisk.com> (raw)
In-Reply-To: <1491850297-18235-1-git-send-email-javier@cnexlabs.com>
On Mon, 2017-04-10 at 20:51 +0200, Javier Gonz=E1lez wrote:
> Convert sprintf calls to snprintf in order to make possible buffer
> overflow more obvious.
>=20
> Signed-off-by: Javier Gonz=E1lez <javier@cnexlabs.com>
> ---
> drivers/lightnvm/core.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>=20
> diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
> index c3340ef..bdbb333 100644
> --- a/drivers/lightnvm/core.c
> +++ b/drivers/lightnvm/core.c
> @@ -272,7 +272,8 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct=
nvm_ioctl_create *create)
> goto err_disk;
> blk_queue_make_request(tqueue, tt->make_rq);
> =20
> - sprintf(tdisk->disk_name, "%s", create->tgtname);
> + snprintf(tdisk->disk_name, sizeof(tdisk->disk_name), "%s",
> + create->tgtname);
> tdisk->flags =3D GENHD_FL_EXT_DEVT;
> tdisk->major =3D 0;
> tdisk->first_minor =3D 0;
> @@ -1195,13 +1196,13 @@ static long nvm_ioctl_get_devices(struct file *fi=
le, void __user *arg)
> list_for_each_entry(dev, &nvm_devices, devices) {
> struct nvm_ioctl_device_info *info =3D &devices->info[i];
> =20
> - sprintf(info->devname, "%s", dev->name);
> + snprintf(info->devname, sizeof(info->devname), "%s", dev->name);
> =20
> /* kept for compatibility */
> info->bmversion[0] =3D 1;
> info->bmversion[1] =3D 0;
> info->bmversion[2] =3D 0;
> - sprintf(info->bmname, "%s", "gennvm");
> + snprintf(info->bmname, sizeof(info->bmname), "%s", "gennvm");
> i++;
> =20
> if (i > 31) {
Hello Javier,
Although the above changes look fine to me, have you considered to use strl=
cpy()
instead of snprintf() for these string copy operations?
Bart.=
next prev parent reply other threads:[~2017-04-10 18:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-10 18:51 [PATCH 1/3] lightnvm: convert sprintf into snprintf Javier González
2017-04-10 18:51 ` [PATCH 2/3] lightnvm: make nvm_free static Javier González
2017-04-11 10:51 ` Matias Bjørling
2017-04-10 18:56 ` Bart Van Assche [this message]
2017-04-11 6:31 ` [PATCH 1/3] lightnvm: convert sprintf into snprintf Javier González
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=1491850565.4199.19.camel@sandisk.com \
--to=bart.vanassche@sandisk.com \
--cc=javier@cnexlabs.com \
--cc=jg@lightnvm.io \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mb@lightnvm.io \
/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).