[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20181014171855.GW32577@ZenIV.linux.org.uk>
Date: Sun, 14 Oct 2018 18:18:55 +0100
From: Al Viro <viro@...IV.linux.org.uk>
To: Christian Brauner <christian@...uner.io>
Cc: keescook@...omium.org, linux-kernel@...r.kernel.org,
ebiederm@...ssion.com, mcgrof@...nel.org,
akpm@...ux-foundation.org, joe.lawrence@...hat.com,
longman@...hat.com
Subject: Re: [PATCH 1/2] sysctl: add overflow detection to proc_get_long()
On Sun, Oct 14, 2018 at 03:25:09PM +0200, Christian Brauner wrote:
> +static unsigned long sysctl_strtoul_lenient(const char *cp, char **endp,
> + unsigned int base, bool *overflow)
> +{
> + unsigned long long result;
> + unsigned int rv;
> +
> + cp = _parse_integer_fixup_radix(cp, &base);
> + rv = _parse_integer(cp, base, &result);
> + if ((rv & KSTRTOX_OVERFLOW) ||
> + (result != (unsigned long long)(unsigned long)result))
> + *overflow = true;
> + else
> + *overflow = false;
Yecchh... First of all, the cast back to unsigned long long is completely
pointless. What's more,
if (expr)
foo = true;
else
foo = flase;
is a fairly unidiomatic way to spell foo = expr;
And... is there anything that would really care if this "overflow" thing had
been replaced by simply returning ~0UL on such? That would appear to be
a lot more natural API...
Powered by blists - more mailing lists