All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>
To: "Greg KH <gregkh@linuxfoundation.org>
	(gregkh@linuxfoundation.org)" <gregkh@linuxfoundation.org>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	"Seymour, Shane M" <shane.seymour@hp.com>,
	"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org
Subject: Re: [PATCH] sysfs.txt: update show method notes about sprintf/snprintf/scnprintf usage
Date: Thu, 25 Jun 2015 16:05:28 +0900	[thread overview]
Message-ID: <20150625070528.GA601@swordfish> (raw)
In-Reply-To: <20150625060305.GA11905@kroah.com>


Cc Jonathan and linux-doc

On (06/24/15 23:03), Greg KH <gregkh@linuxfoundation.org> (gregkh@linuxfoundation.org) wrote:
[..]
> > > -- show() should always use scnprintf().
> > > +- show() must not use snprintf() when formatting a value to be
> > > +  returned to user space. For small single values you can use
> > > +  sprintf() otherwise you must use scnprintf().
> > 
> > Well, a single value can easily overflow
> > 
> > 	sprintf(buf, "%s", dev->large_value);
> 
> That's an obviously foolish sysfs attribute, if you do that, you deserve
> the kernel crash :)

:)

And the 'always use scnprintf()' rule keeps all of us on the safe
side (almost for free).

> > Probably the wording better be "if you guarantee that overflow will
> > never happen, then you can use ...".
> 
> For a document that no one has obviously read in the past 5 years, I
> really doubt we need to work too hard on the exact specific wording of
> it.

Oh, it's especially pleasant and satisfactory to ignore
a well-written and scrupulous documentation  :)  just kidding.

	-ss

      reply	other threads:[~2015-06-25  7:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25  0:55 [PATCH] sysfs.txt: update show method notes about sprintf/snprintf/scnprintf usage Seymour, Shane M
     [not found] ` <DDB9C85B850785449757F9914A034FCB3F8EA364-MCKW7lC+H9ISZAcGdq5asR6epYMZPwEe5NbjCUgZEJk@public.gmane.org>
2015-06-25  1:59   ` Sergey Senozhatsky
2015-06-25  6:03     ` Greg KH <gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org> (gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org)
2015-06-25  7:05       ` Sergey Senozhatsky [this message]

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=20150625070528.GA601@swordfish \
    --to=sergey.senozhatsky.work@gmail.com \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=shane.seymour@hp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.