kernel-hardening.lists.openwall.com archive mirror
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Yann Droneaud <ydroneaud@opteya.com>,
	David Laight <David.Laight@ACULAB.COM>,
	Joe Perches <joe@perches.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>, Stephen Kitt <steve@sk2.org>,
	Kees Cook <keescook@chromium.org>,
	Nitin Gote <nitin.r.gote@intel.com>,
	"jannh@google.com" <jannh@google.com>,
	"kernel-hardening@lists.openwall.com"
	<kernel-hardening@lists.openwall.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms
Date: Wed, 24 Jul 2019 15:09:10 +0200	[thread overview]
Message-ID: <396d1eed-8edf-aa77-110b-c50ead3a5fd5@rasmusvillemoes.dk> (raw)
In-Reply-To: <bc1ad99a420dd842ce3a17c2c38a2f94683dc91c.camel@opteya.com>

On 24/07/2019 14.05, Yann Droneaud wrote:
> Hi,
> 

> Beware that snprintf(), per C standard, is supposed to return the
> length of the formatted string, regarless of the size of the
> destination buffer.
> 
> So encouraging developper to write something like code below because
> snprintf() in kernel behave in a non-standard way,

The kernel's snprintf() does not behave in a non-standard way, at least
not with respect to its return value. It doesn't support %n or floating
point, of course, and there are some quirks regarding precision (see
lib/test_printf.c for details).

There's the non-standard scnprintf() for getting the length of the
formatted string, which can safely be used in an append loop. Or one can
use the seq_buf API.

Rasmus

  reply	other threads:[~2019-07-24 13:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23  0:38 [PATCH 0/2] string: Add stracpy and stracpy_pad Joe Perches
2019-07-23  0:38 ` [PATCH 1/2] string: Add stracpy and stracpy_pad mechanisms Joe Perches
2019-07-23  4:35   ` Andrew Morton
2019-07-23  4:42     ` Joe Perches
2019-07-23 21:29       ` Kees Cook
2019-07-23  6:55   ` Rasmus Villemoes
2019-07-23 15:41     ` David Laight
2019-07-23 15:50       ` Joe Perches
2019-07-23 21:34       ` Kees Cook
2019-07-24 12:05       ` Yann Droneaud
2019-07-24 13:09         ` Rasmus Villemoes [this message]
2019-07-24 17:08           ` Linus Torvalds
2019-07-25 20:03             ` Kees Cook
2019-07-26  2:46               ` Joe Perches
2019-07-23 21:36   ` Kees Cook
2019-07-24 11:40     ` Joe Perches
2019-07-23  0:38 ` [PATCH 2/2] kernel-doc: core-api: Include string.h into core-api Joe Perches
2019-07-23 21:28   ` Kees Cook

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=396d1eed-8edf-aa77-110b-c50ead3a5fd5@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=David.Laight@ACULAB.COM \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=jannh@google.com \
    --cc=joe@perches.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nitin.r.gote@intel.com \
    --cc=steve@sk2.org \
    --cc=torvalds@linux-foundation.org \
    --cc=ydroneaud@opteya.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 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).