Date: Fri, 13 Feb 2015 10:59:50 +0300 From: Andrey Chernov <ache@freebsd.org> To: Bruce Evans <brde@optusnet.com.au>, "Bjoern A. Zeeb" <bz@freebsd.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, Pedro Giffuni <pfg@freebsd.org>, src-committers@freebsd.org Subject: Re: svn commit: r278634 - head/lib/libc/gen Message-ID: <54DDAEF6.3060900@freebsd.org> In-Reply-To: <54DDABF2.9000201@freebsd.org> References: <201502122107.t1CL7gaO004041@svn.freebsd.org> <BF5F2941-52F5-41A4-8723-E316919718EE@FreeBSD.org> <54DD2A87.2050008@FreeBSD.org> <9A683D99-C1E9-4736-982C-69F583D3A40D@FreeBSD.org> <20150213172738.C1007@besplex.bde.org> <54DDABF2.9000201@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
We even don't need to check arg excepting for < 0, because what is
needed is rlimt_t and not arg. So this version will be better:
rlimt_t targ;
if (arg < 0) {
errno = EINVAL;
return (-1);
}
targ = arg;
if (targ > RLIM_INFINITY / 512)
targ = RLIM_INFINITY / 512;
limit.rlim_max = limit.rlim_cur = targ * 512
On 13.02.2015 10:46, Andrey Chernov wrote:
> On 13.02.2015 10:18, Bruce Evans wrote:
>> if (arg > RLIM_INFINITY)
>> err(...);
>
> Checking for RLIM_INFINITY is wrong here, since it is ulong long max,
> considering
> arg = va_arg(ap, long);
> and ulimit(3) stating that arg is always plain long.
>
> Proper check will be
>
> if (arg < 0) {
> errno = EINVAL;
> return (-1);
> }
> if (arg > LONG_MAX / 512)
> arg = LONG_MAX / 512;
>
> That all. In pure theoretical case RLIM_INFINITY is less than LONG_MAX,
> it is job of underlying setrlimit(2) to return error.
>
--
http://ache.vniz.net/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54DDAEF6.3060900>
