From: Giel van Schijndel <me@mortis.eu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Brian King <brking@us.ibm.com>,
"James E.J. Bottomley" <JBottomley@parallels.com>,
"open list:SCSI SUBSYSTEM" <linux-scsi@vger.kernel.org>
Subject: Re: [PATCH] Cleanup: snprintf() always NUL-terminates: depend on it
Date: Sun, 4 Jan 2015 23:38:00 +0100 [thread overview]
Message-ID: <20150104223800.GA4806@salidar.dom.custoft.eu> (raw)
In-Reply-To: <CA+55aFw8aMBF5uXekxATymQPTqwZHGJTL-jQx8zDqOwbaft+4g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1602 bytes --]
On Sun, Jan 04, 2015 at 11:34:43 -0800, Linus Torvalds wrote:
> On Sun, Jan 4, 2015 at 10:05 AM, Giel van Schijndel <me@mortis.eu> wrote:
>> Especially since one very strange piece of code seems to be written in
>> such a way that a NUL needs to be placed where a NUL is present already.
>
> Actually, it's worse than that. This:
>
>> len = snprintf(fname, 99, "%s", buf);
>> - fname[len-1] = '\0';
>
> is complete garbage, since the return value of snprintf() is not the
> length of the result, but length of what the result *would* have been.
>
> So if the string doesn't fit in 99 bytes, it will actively corrupt
> some random memory after the string. It's not writing zero to what was
> already zero, it's corrupting memory.
Ah yes, I didn't even notice that nasty side effect. I just deleted that
"really, really" NUL-termination line because it was based on a
misunderstanding of snprintf()'s postcondition. Even if
len==sizeof(fname) this still would have given the wrong example for
others to follow.
> Anyway, from a quick glance your patches look fine, but you need to
> sign off on them. See Documentation/SubmittingPatches.
Ah yes, forgot that. Would it be sufficient if I sent a reply to all
those patch mails with next line tacked on, or would it require a
resubmission?
> Signed-off-by: Giel van Schijndel <me@mortis.eu>
--
Met vriendelijke groet,
With kind regards,
Giel van Schijndel
--
"Always code as if the guy who ends up maintaining your code will be a
violent psychopath who knows where you live."
-- Rick Osborne
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2015-01-04 22:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-04 18:05 Giel van Schijndel
2015-01-04 19:34 ` Linus Torvalds
2015-01-04 22:38 ` Giel van Schijndel [this message]
2015-01-04 23:05 ` Giel van Schijndel
2015-01-07 19:20 ` [PATCH RESEND] scsi: cleanup: " Giel van Schijndel
2015-01-12 9:07 [PATCH] Cleanup: " Aleksandr P
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=20150104223800.GA4806@salidar.dom.custoft.eu \
--to=me@mortis.eu \
--cc=JBottomley@parallels.com \
--cc=brking@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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
all inboxes | Powered by JetHome®