linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bodo Eggert <arcoristkaputtundbrauchtdiesentext.7eggert@nurfuerspam.de>
To: Michael Tokarev <mjt@tls.msk.ru>, "Daniel K." <dk@uw.no>,
	Jesper Juhl <jj@chaosbits.net>,
	linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org,
	Neil Brown <neilb@suse.de>Neil
Subject: Re: [PATCH] md: Remove risk of overflow via sprintf) by using snprintf()  in md_check_recovery()
Date: Sun, 13 Feb 2011 21:53:21 +0100	[thread overview]
Message-ID: <E1Poiwb-0002rc-Lm@be1.7eggert.dyndns.org> (raw)
In-Reply-To: glo1k-1AX-17@gated-at.bofh.it

Michael Tokarev <mjt@tls.msk.ru> wrote:
> 12.02.2011 12:34, Daniel K. wrote:
>> 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);

> C'mon guys, this is pointless.  20 bytes allocated for the device
> name, and this is for raid disk number.  It is impossible to have
> more than 10^17 (20 bytes total, 2 for "rd" and on for the zero
> terminator) drives in a single array.

If you argue that you might get a buffer overflow, you'll have to check
for snprintf errors, too.
-- 
Logic: The art of being wrong with confidence... 

Friß, Spammer: tR@c.7eggert.dyndns.org S5xk@h.7eggert.dyndns.org
 loqnjg@GFhzy.7eggert.dyndns.org 6hs4Axaqf@ndlJ.7eggert.dyndns.org

       reply	other threads:[~2011-02-13 20:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [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 [this message]
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.
2011-02-12 13:48   ` Michael Tokarev
2011-02-12 14:06     ` Daniel K.
2011-02-13 20:18       ` Jesper Juhl

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=E1Poiwb-0002rc-Lm@be1.7eggert.dyndns.org \
    --to=arcoristkaputtundbrauchtdiesentext.7eggert@nurfuerspam.de \
    --cc=7eggert@nurfuerspam.de \
    --cc=dk@uw.no \
    --cc=jj@chaosbits.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=mjt@tls.msk.ru \
    --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).