library: beef up 'enum pids_item' parameter validation
I was surprised to find that ol' gcc silently converts a single (different) enum into an address where one or more enums were expected to be dereferenced. Of course this was just yet another way to generate an old SEGV. So this commit will strengthen those parameter checks. [ we will *not* blame Craig for a failure to consult ] [ the documentation, since it doesn't even exist yet ] Reference(s): http://www.freelists.org/post/procps/newlib-ps-fix,8 Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
e2898e213f
commit
eba58ec17a
11
proc/pids.c
11
proc/pids.c
@ -793,6 +793,17 @@ static inline int items_check_failed (
|
||||
{
|
||||
int i;
|
||||
|
||||
/* if an enum is passed instead of an address of one or more enums, ol' gcc
|
||||
* will silently convert it to an address (possibly NULL). only clang will
|
||||
* offer any sort of warning like the following:
|
||||
*
|
||||
* warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'enum pids_item *'
|
||||
* if (procps_pids_new(&info, 3, PROCPS_PIDS_noop) < 0)
|
||||
* ^~~~~~~~~~~~~~~~
|
||||
*/
|
||||
if (maxitems < 1
|
||||
|| (void *)items < (void *)PROCPS_PIDS_physical_end)
|
||||
return -1;
|
||||
for (i = 0; i < maxitems; i++) {
|
||||
// a pids_item is currently unsigned, but we'll protect our future
|
||||
if (items[i] < 0)
|
||||
|
Loading…
Reference in New Issue
Block a user