[PATCH] setrlimit/getrlimit: Add parameter check to prevent null pointer access
Zack Weinberg
zackw@panix.com
Sun Jan 3 04:22:57 GMT 2021
On Sat, Jan 2, 2021 at 10:20 PM Xiaoming Ni wrote:
> __nonnull((2)) can only check null pointers in the compilation phase,
As an external interface, the getrlimit()/setrlimit()/prlimit() needs to
> check the null pointer during the running of the code to prevent the
> system from crashing.
This is a common misconception. Most C library functions *should* crash the
process when they receive invalid pointer arguments.
To implement getrlimit on top of prlimit, you need to do something like
this:
memset (rlim, 0, sizeof *rlim);
return prlimit (0, rsrc, 0, rlim);
so that the program crashes instead of doing nothing when rlim is null.
zw
>
More information about the Libc-alpha
mailing list