Re: [RFC][CFLART] ipmi procfs bogosity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[email protected] 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux