diff options
author | pfg <pfg@FreeBSD.org> | 2015-02-12 21:07:42 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2015-02-12 21:07:42 +0000 |
commit | 54c59fd68969bf0a48e1a95ee272a74ea14fecab (patch) | |
tree | 93abbba0a37143b3012ea63826ed970a17eb36ca /lib/libc | |
parent | 0b5bdf57784feeaa96b7eebb84262c16894769c9 (diff) | |
download | FreeBSD-src-54c59fd68969bf0a48e1a95ee272a74ea14fecab.zip FreeBSD-src-54c59fd68969bf0a48e1a95ee272a74ea14fecab.tar.gz |
ulimit(3): Fix broken check.
The existing implementation had a broken comparison that could overflow.
Replace this with a check that avoids the overflow before it happens.
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().
Discussed with: bde (rather extensively)
CID: 1199295
MFC after: 1 week
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/ulimit.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/libc/gen/ulimit.c b/lib/libc/gen/ulimit.c index e1bc020..9f9c912 100644 --- a/lib/libc/gen/ulimit.c +++ b/lib/libc/gen/ulimit.c @@ -53,13 +53,13 @@ ulimit(int cmd, ...) va_start(ap, cmd); arg = va_arg(ap, long); va_end(ap); + if (arg > RLIM_INFINITY / 512 || arg < 0) + arg = RLIM_INFINITY / 512; limit.rlim_max = limit.rlim_cur = (rlim_t)arg * 512; /* The setrlimit() function sets errno to EPERM if needed. */ if (setrlimit(RLIMIT_FSIZE, &limit) == -1) return (-1); - if (arg * 512 > LONG_MAX) - return (LONG_MAX); return (arg); } else { errno = EINVAL; |