Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Feb 2015 22:27:41 +0000
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        "Pedro F. Giffuni" <pfg@FreeBSD.org>
Cc:        svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org
Subject:   Re: svn commit: r278634 - head/lib/libc/gen
Message-ID:  <BF5F2941-52F5-41A4-8723-E316919718EE@FreeBSD.org>
In-Reply-To: <201502122107.t1CL7gaO004041@svn.freebsd.org>
References:  <201502122107.t1CL7gaO004041@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

> On 12 Feb 2015, at 21:07 , Pedro F. Giffuni <pfg@FreeBSD.org> wrote:
>=20
> Author: pfg
> Date: Thu Feb 12 21:07:42 2015
> New Revision: 278634
> URL: https://svnweb.freebsd.org/changeset/base/278634
>=20
> Log:
>  ulimit(3): Fix broken check.
>=20
>  The existing implementation had a broken comparison that could =
overflow.
>  Replace this with a check that avoids the overflow before it happens.
>=20
>  Consistently return a maximum value also on the case of negative
>  arguments since negative is considered an overflow and means
>  infinity for our current setrlimit().
>=20
>  Discussed with:	bde (rather extensively)
>=20

Did this compile?


>  CID:		1199295
>  MFC after:	1 week
>=20
> Modified:
>  head/lib/libc/gen/ulimit.c
>=20
> Modified: head/lib/libc/gen/ulimit.c
> =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
> --- head/lib/libc/gen/ulimit.c	Thu Feb 12 20:57:57 2015	=
(r278633)
> +++ head/lib/libc/gen/ulimit.c	Thu Feb 12 21:07:42 2015	=
(r278634)
> @@ -53,13 +53,13 @@ ulimit(int cmd, ...)
> 		va_start(ap, cmd);
> 		arg =3D va_arg(ap, long);
> 		va_end(ap);
> +		if (arg > RLIM_INFINITY / 512 || arg < 0)
> +			arg =3D RLIM_INFINITY / 512;
> 		limit.rlim_max =3D limit.rlim_cur =3D (rlim_t)arg * 512;
>=20
> 		/* The setrlimit() function sets errno to EPERM if =
needed. */
> 		if (setrlimit(RLIMIT_FSIZE, &limit) =3D=3D -1)
> 			return (-1);
> -		if (arg * 512 > LONG_MAX)
> -			return (LONG_MAX);
> 		return (arg);
> 	} else {
> 		errno =3D EINVAL;
>=20

=E2=80=94=20
Bjoern A. Zeeb                                  Charles Haddon Spurgeon:
"Friendship is one of the sweetest joys of life.  Many might have failed
 beneath the bitterness of their trial  had they not found a friend."




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BF5F2941-52F5-41A4-8723-E316919718EE>