public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "George Spelvin" <linux@horizon.com>
To: andrei.emeltchenko@intel.com, andriy.shevchenko@linux.intel.com,
	gang.chen@asianux.com, jkosina@suse.cz, linux@horizon.com
Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/vsprintf.c: fix the incorrect return value of vsnprintf()
Date: 18 Jul 2013 02:42:38 -0400	[thread overview]
Message-ID: <20130718064238.25532.qmail@science.horizon.com> (raw)
In-Reply-To: <51E78B21.50907@asianux.com>

> When "str >= end", necessary to reset 'str' to "end - 1", or the return
> value will be larger than the real one, the callers which depend on the
> return value, may cause memory overflow.

NAK.  This is the documented (by both the function itself and the
ANSI/ISO C standard) and desired return value: the number of bytes that
*would* have been in the output string if the buffer were large enough.
In particular, it is common to do:

size = vsnprintf(NULL, 0, fmt, args) + 1;
p = malloc(size, GFP_KERNEL);
vsnprintf(p, size, fmt, args);

You want vscnprintf.  If you have a caller that needs the *actual* number of
bytes written, use that.

  reply	other threads:[~2013-07-18  6:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-18  6:28 [PATCH] lib/vsprintf.c: fix the incorrect return value of vsnprintf() Chen Gang
2013-07-18  6:42 ` George Spelvin [this message]
2013-07-18  6:50   ` Chen Gang
2013-07-18  6:49 ` Al Viro
2013-07-18  6:52   ` Chen Gang

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=20130718064238.25532.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrei.emeltchenko@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=gang.chen@asianux.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.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