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:
@@ -1282,7 +1282,7 @@ PROCPS_EXPORT struct vmstat_result *xtra_vmstat_get (
|
||||
} // end: xtra_vmstat_get_
|
||||
|
||||
|
||||
PROCPS_EXPORT void xtra_vmstat_val (
|
||||
PROCPS_EXPORT struct vmstat_result *xtra_vmstat_val (
|
||||
int relative_enum,
|
||||
const char *typestr,
|
||||
const struct vmstat_stack *stack,
|
||||
@@ -1290,17 +1290,21 @@ PROCPS_EXPORT void xtra_vmstat_val (
|
||||
const char *file,
|
||||
int lineno)
|
||||
{
|
||||
struct vmstat_result *r;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
r = &stack->head[relative_enum];
|
||||
if (r->item < 0 || r->item >= VMSTAT_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 < VMSTAT_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_vmstat_val
|
||||
|
Reference in New Issue
Block a user