svn commit: r278634 - head/lib/libc/gen

Andrey Chernov ache at freebsd.org
Fri Feb 13 17:37:29 UTC 2015


On 13.02.2015 17:29, Bruce Evans wrote:
>> if (arg < 0) {
>>    errno = EINVAL;
>>    return (-1);
>> }
> 
> 
> This is reasonable, but not encouraged by the API or compatible with
> what setrlimit() does with negative args.  (setrlimit() still uses
> my hack from 1994, of converting negative args to RLIM_INFINITY.  In
> 4.4BSD, it doesn't even check for negative args, and mostly stores
> them unchanged; then undefined behaviour tends to occur when the
> stored values are used without further checking.)

This hack should be removed from setrlimit() to catch real error.
Any syscall should do basic arguments validation.
This is true about ulimit() too, so it is not a syscall. If overflow
happens before passing arg, it is better to report it than to convert
blindly to RLIM_INFINITY.
Somebody may decrement long limit value by fixed chunks and go beyond
zero. I.e. situation is completely opposite: he means 0 limit, but you
set it to INFINITY. So it is always better to report error to leave
caller deal with it. If he needs a bigger than long limit, he should use
setrlimit() directly, not ulimit().

-- 
http://ache.vniz.net/


More information about the svn-src-all mailing list