All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 01/10] Add parse_integer() (replacement for simple_strto*())
Date: Mon, 04 May 2015 23:48:27 +0200	[thread overview]
Message-ID: <87383cui8k.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <20150504195435.GA21686@p183.telecom.by> (Alexey Dobriyan's message of "Mon, 4 May 2015 22:54:35 +0300")

On Mon, May 04 2015, Alexey Dobriyan <adobriyan@gmail.com> wrote:

>> There are lots of callers of memparse(), and I don't think any of them
>> are prepared to handle *endp ending up pointing before the passed-in
>> string (-EINVAL == -22, -ERANGE == -34). I can easily see how that could
>> lead to an infinite loop, maybe worse.
>
> Yeah, possible bug could become worse, I'll add error checking,
> but, seriously, you're defending this :^)
>
> 	case Opt_nr_inodes:
> ===>		/* memparse() will accept a K/M/G without a digit */
> ===>		if (!isdigit(*args[0].from))
> ===>			goto bad_val;
> 		pconfig->nr_inodes = memparse(args[0].from, &rest);
> 		break;
>

No, I'm not defending memparse(), simple_strto* or any of their
callers. I'm just trying to say that you can't change the semantics of
memparse() without considering all its callers.

I don't think there's any way to "add error checking" and preserve the
exact memparse() semantic - in other words, I don't think simple_strto*
can actually be implemented in terms of parse_integer. But that's not a
bad thing - we want to get rid of those.

> memparse() is misdesigned in the same sense strtoul() is misdesigned.
> Every "memparse(s, NULL)" user is a bug for example.

Yes, memparse is misdesigned, since it doesn't have a way to indicate
error. That leads me to: There's no point in adding error checking to
the integer parsing part without also checking the left shifts for
overflow.

I think the right approach is to rename memparse to legacy_memparse and
introduce a memparse with semantics that allow error checking. One could
start by introducing that under the name sane_memparse. But there are
probably lots of simple_strto*() uses that are easier to eliminate.

Rasmus

      reply	other threads:[~2015-05-04 21:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-02  0:47 [PATCH 01/10] Add parse_integer() (replacement for simple_strto*()) Alexey Dobriyan
2015-05-02  0:48 ` [PATCH 02/10] parse_integer: rewrite kstrto*() Alexey Dobriyan
2015-05-02  0:50 ` [PATCH 03/10] parse_integer: convert sscanf() Alexey Dobriyan
2015-05-02  1:10   ` [PATCH CORRECT " Alexey Dobriyan
2015-05-02  0:51 ` [PATCH 04/10] sscanf: fix overflow Alexey Dobriyan
2015-05-05  9:51   ` Rasmus Villemoes
2015-05-05 11:10     ` Alexey Dobriyan
2015-05-06  7:49       ` Rasmus Villemoes
2015-05-02  0:53 ` [PATCH 05/10] parse_integer: convert lib/ Alexey Dobriyan
2015-05-04 14:10   ` Rasmus Villemoes
2015-05-04 14:57     ` Alexey Dobriyan
2015-05-02  0:55 ` [PATCH 06/10] parse_integer: convert mm/ Alexey Dobriyan
2015-05-04 14:33   ` Rasmus Villemoes
2015-05-04 15:09     ` Alexey Dobriyan
2015-05-02  0:56 ` [PATCH 07/10] parse_integer: convert misc fs/ code Alexey Dobriyan
2015-05-02  0:59 ` [PATCH 08/10] fs/cachefiles/: convert to parse_integer() Alexey Dobriyan
2015-05-02  1:01 ` [PATCH 09/10] ocfs2: convert to parse_integer()/kstrto*() Alexey Dobriyan
2015-05-02  1:03 ` [PATCH 10/10] ext2, ext3, ext4: " Alexey Dobriyan
2015-05-04 13:24 ` [PATCH 01/10] Add parse_integer() (replacement for simple_strto*()) Rasmus Villemoes
2015-05-04 14:32   ` Alexey Dobriyan
2015-05-04 16:44     ` Rasmus Villemoes
2015-05-04 19:54       ` Alexey Dobriyan
2015-05-04 21:48         ` Rasmus Villemoes [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=87383cui8k.fsf@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --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 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.