library: strengthen the VAL macro validation functions

One ought not to assume that random memory access will
always succeed or, when it does, that an obviously bad
item enumerator will always be found at that location.

Thus, this patch corrects some really poor assumptions
associated with the 'xtra_procps_debug.h' header file.

[ and it does so in somewhat contorted ways so as to ]
[ avoid several darn gcc -Wnonnull warning messages! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2016-08-08 01:23:45 -05:00
committed by Craig Small
parent 6b6ad95f40
commit 9f27e9d8d9
7 changed files with 102 additions and 72 deletions

View File

@ -1161,7 +1161,7 @@ PROCPS_EXPORT struct stat_result *xtra_stat_get (
} // end: xtra_stat_get_
PROCPS_EXPORT void xtra_stat_val (
PROCPS_EXPORT struct stat_result *xtra_stat_val (
int relative_enum,
const char *typestr,
const struct stat_stack *stack,
@ -1169,17 +1169,21 @@ PROCPS_EXPORT void xtra_stat_val (
const char *file,
int lineno)
{
struct stat_result *r;
char *str;
int i;
r = &stack->head[relative_enum];
if (r->item < 0 || r->item >= STAT_logical_end) {
fprintf(stderr, "%s line %d: invalid item = %d, relative_enum = %d, type = %s\n"
, file, lineno, r->item, relative_enum, typestr);
return;
for (i = 0; stack->head[i].item < STAT_logical_end; i++)
;
if (relative_enum < 0 || relative_enum >= i) {
fprintf(stderr, "%s line %d: invalid relative_enum = %d, type = %s\n"
, file, lineno, relative_enum, typestr);
return NULL;
}
str = Item_table[r->item].type2str;
str = Item_table[stack->head[relative_enum].item].type2str;
if (str[0]
&& (strcmp(typestr, str)))
&& (strcmp(typestr, str))) {
fprintf(stderr, "%s line %d: was %s, expected %s\n", file, lineno, typestr, str);
return NULL;
}
return &stack->head[relative_enum];
} // end: xtra_stat_val