From: Corey Minyard <minyard@acm.org>
To: viro@ZenIV.linux.org.uk
Cc: Matt_Domsch@Dell.com, Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC][CFLART] ipmi procfs bogosity
Date: Thu, 01 Sep 2005 15:00:44 -0500 [thread overview]
Message-ID: <43175DEC.4000600@acm.org> (raw)
In-Reply-To: <20050901193201.GD26264@ZenIV.linux.org.uk>
viro@ZenIV.linux.org.uk wrote:
>On Thu, Sep 01, 2005 at 11:41:42AM -0500, Corey Minyard wrote:
>
>
>>Indeed, this function is badly written. In rewriting, I couldn't find a
>>nice function for reading integers from userspace, and the proc_dointvec
>>stuff didn't seem terribly suitable. So I wrote my own general
>>function, which I can move someplace else if someone likes. Patch is
>>attached. It should not affect correct usage of this file.
>>
>>
>
>Eeeek... Much, _much_ simpler approach would be to have
>
> char buf[10];
> if (count > 9)
> return -EINVAL;
> if (copy_from_user(buf, buffer, count))
> return -EFAULT;
> buf[count] = '\0';
> /* use sscanf() or anything normal */
>
>Would that change behaviour in any cases you care about?
>
>
Because then, for a general solution that avoids integer
perversion, you need something like:
char buf[10];
char *end;
if (count > (sizeof(buf) - 1))
return -EINVAL;
if (copy_from_user(buf, buffer, count))
return -EFAULT;
buf[count] = '\0';
newval = simple_strtoul(buf, &end, 0);
if (buf == end)
/* Empty string or first char not a number */
return -EINVAL;
if (*end && ! isspace(*end))
/* Bogus number. */
return -EINVAL;
To me, It's a lot nicer to do:
rv = user_strtoul(....);
if (rv < 0)
return rv;
Plus the scanning function I wrote handles arbitrary leading and
trailing space, etc. Not a big deal, but a little nicer.
-Corey
next prev parent reply other threads:[~2005-09-01 20:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-01 6:43 [RFC][CFLART] ipmi procfs bogosity viro
2005-09-01 16:41 ` Corey Minyard
2005-09-01 19:32 ` viro
2005-09-01 20:00 ` Corey Minyard [this message]
2005-09-01 20:30 ` Alexey Dobriyan
2005-09-05 10:51 ` Ingo Oeser
2005-09-05 19:38 ` Alexey Dobriyan
2005-09-01 19:41 ` Andrew Morton
2005-09-01 23:03 ` Corey Minyard
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=43175DEC.4000600@acm.org \
--to=minyard@acm.org \
--cc=Matt_Domsch@Dell.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@ZenIV.linux.org.uk \
/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