library: ensure that all those 'GET' macros are robust
When users call the native 'get' functions they have a responsibility to check that the result struct address was indeed returned. But when using those 'GET' macros there was no protection for possible NULL dereference. So this patch will add some protection for a potential failure of an underlying 'get' function. And should it occur then those 'GET' macros will just return a zero. Plus, we'll also mirror that behavior in the debugging header should the XTRA_PROCPS_DEBUG #define be active. And, we might as well add a warning when invalid items are passed to 'GET' macros, just like we do for 'VAL'. [ lastly, we added the missing opening parens/braces ] [ to 2 'GET' macros in that xtra-procps-debug.h file ] [ which went unnoticed until the qa folks caught up. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
@@ -1147,6 +1147,10 @@ PROCPS_EXPORT struct stat_result *xtra_stat_get (
|
||||
{
|
||||
struct stat_result *r = procps_stat_get(info, actual_enum);
|
||||
|
||||
if (actual_enum < 0 || actual_enum >= STAT_logical_end) {
|
||||
fprintf(stderr, "%s line %d: invalid item = %d, type = %s\n"
|
||||
, file, lineno, actual_enum, typestr);
|
||||
}
|
||||
if (r) {
|
||||
char *str = Item_table[r->item].type2str;
|
||||
if (str[0]
|
||||
|
Reference in New Issue
Block a user