library: optional parms protection missing, <PIDS> api

When those items were made dynamic at 'new' time, some
other functions, previously assured of their presence,
failed to verify a 'reset' had acually been requested.

This commit just corrects that oversight and avoids an
attempt to 'assign_results' when no items are present.

Reference(s):
. when items/numitems became optional
commit 9ebadc1438

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2016-06-15 00:00:00 -05:00 committed by Craig Small
parent 5ce94f9bb0
commit d7100d071d

View File

@ -876,8 +876,8 @@ static void itemize_stacks_all (
static inline int items_check_failed ( static inline int items_check_failed (
int numitems, enum pids_item *items,
enum pids_item *items) int numitems)
{ {
int i; int i;
@ -1137,7 +1137,7 @@ PROCPS_EXPORT int procps_pids_new (
/* if we're without items or numitems, a later call to /* if we're without items or numitems, a later call to
procps_pids_reset() will become mandatory */ procps_pids_reset() will become mandatory */
if (items && numitems) { if (items && numitems) {
if (items_check_failed(numitems, items)) { if (items_check_failed(items, numitems)) {
free(p); free(p);
return -EINVAL; return -EINVAL;
} }
@ -1242,15 +1242,23 @@ PROCPS_EXPORT struct pids_stack *fatal_proc_unmounted (
static proc_t self; static proc_t self;
struct stacks_extent *ext; struct stacks_extent *ext;
// this is very likely the *only* newlib function where the /* this is very likely the *only* newlib function where the
// context (procps_pidsinfo) of NULL will ever be permitted context (procps_pidsinfo) of NULL will ever be permitted */
look_up_our_self(&self); look_up_our_self(&self);
if (!return_self) if (!return_self)
return NULL; return NULL;
if (info == NULL if (info == NULL)
|| !(ext = stacks_alloc(info, 1)) return NULL;
|| !extent_cut(info, ext))
/* with items & numitems technically optional at 'new' time, it's
expected 'reset' will have been called -- but just in case ... */
if (!info->curitems)
return NULL;
if (!(ext = stacks_alloc(info, 1)))
return NULL;
if (!extent_cut(info, ext))
return NULL; return NULL;
ext->next = info->otherexts; ext->next = info->otherexts;
@ -1273,6 +1281,10 @@ PROCPS_EXPORT struct pids_stack *procps_pids_get (
return NULL; return NULL;
if (which != PROCPS_FETCH_TASKS_ONLY && which != PROCPS_FETCH_THREADS_TOO) if (which != PROCPS_FETCH_TASKS_ONLY && which != PROCPS_FETCH_THREADS_TOO)
return NULL; return NULL;
/* with items & numitems technically optional at 'new' time, it's
expected 'reset' will have been called -- but just in case ... */
if (!info->curitems)
return NULL;
fresh_start: fresh_start:
if (!info->get_ext) { if (!info->get_ext) {
@ -1318,10 +1330,12 @@ PROCPS_EXPORT struct pids_fetch *procps_pids_reap (
if (info == NULL) if (info == NULL)
return NULL; return NULL;
if (!info->curitems)
return NULL;
if (which != PROCPS_FETCH_TASKS_ONLY && which != PROCPS_FETCH_THREADS_TOO) if (which != PROCPS_FETCH_TASKS_ONLY && which != PROCPS_FETCH_THREADS_TOO)
return NULL; return NULL;
/* with items & numitems technically optional at 'new' time, it's
expected 'reset' will have been called -- but just in case ... */
if (!info->curitems)
return NULL;
if (!oldproc_open(&info->PT, info->oldflags)) if (!oldproc_open(&info->PT, info->oldflags))
return NULL; return NULL;
@ -1342,7 +1356,7 @@ PROCPS_EXPORT int procps_pids_reset (
{ {
if (info == NULL || newitems == NULL) if (info == NULL || newitems == NULL)
return -EINVAL; return -EINVAL;
if (items_check_failed(newnumitems, newitems)) if (items_check_failed(newitems, newnumitems))
return -EINVAL; return -EINVAL;
/* shame on this caller, they didn't change anything. and unless they have /* shame on this caller, they didn't change anything. and unless they have
@ -1398,6 +1412,10 @@ PROCPS_EXPORT struct pids_fetch *procps_pids_select (
return NULL; return NULL;
if (which != PROCPS_SELECT_PID && which != PROCPS_SELECT_UID) if (which != PROCPS_SELECT_PID && which != PROCPS_SELECT_UID)
return NULL; return NULL;
/* with items & numitems technically optional at 'new' time, it's
expected 'reset' will have been called -- but just in case ... */
if (!info->curitems)
return NULL;
// this zero delimiter is really only needed with PROCPS_SELECT_PID // this zero delimiter is really only needed with PROCPS_SELECT_PID
memcpy(ids, these, sizeof(unsigned) * numthese); memcpy(ids, these, sizeof(unsigned) * numthese);