From: "Daniel K." <dk@uw.no>
To: Jesper Juhl <jj@chaosbits.net>
Cc: linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org,
Neil Brown <neilb@suse.de>, Neil Brown <neilb@cse.unsw.edu.au>
Subject: Re: [PATCH] md: Remove risk of overflow via sprintf) by using snprintf() in md_check_recovery()
Date: Sat, 12 Feb 2011 09:34:21 +0000 [thread overview]
Message-ID: <4D56541D.3030409@uw.no> (raw)
In-Reply-To: <alpine.LNX.2.00.1102112227040.16994@swampdragon.chaosbits.net>
Jesper Juhl wrote:
> sprintf() is dangerous - given the wrong source string it will overflow
> the destination. snprintf() is safer in that at least we'll never overflow
> the destination. Even if overflow will never happen today, code changes
> over time and snprintf() is just safer in the long run.
> - sprintf(nm,"rd%d", rdev->raid_disk);
> + snprintf(nm, sizeof(nm), "rd%d", rdev->raid_disk);
> sysfs_remove_link(&mddev->kobj, nm);
What if "rd1234" get truncated to "rd123" and you remove the wrong link.
(No, I didn't actually bother to check how much room was allocated.)
Isn't it better to overflow than silently to unlink the wrong file?
What will happen when you try to unlink the "rd123" file again, when the
actual 123 is meant?
Whatever the real fix is, should this be checked for at create_link time
as well?
Daniel K.
next prev parent reply other threads:[~2011-02-12 9:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-11 21:30 [PATCH] md: Remove risk of overflow via sprintf) by using snprintf() in md_check_recovery() Jesper Juhl
2011-02-12 9:34 ` Daniel K. [this message]
2011-02-12 13:48 ` Michael Tokarev
2011-02-12 14:06 ` Daniel K.
2011-02-13 20:18 ` Jesper Juhl
[not found] <gl8SB-1hb-11@gated-at.bofh.it>
[not found] ` <glk7o-3l2-17@gated-at.bofh.it>
[not found] ` <glo1k-1AX-17@gated-at.bofh.it>
2011-02-13 20:53 ` Bodo Eggert
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=4D56541D.3030409@uw.no \
--to=dk@uw.no \
--cc=jj@chaosbits.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-raid@vger.kernel.org \
--cc=neilb@cse.unsw.edu.au \
--cc=neilb@suse.de \
/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).