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:
parent
105058ae2d
commit
bef8c7fb70
@ -1000,6 +1000,10 @@ PROCPS_EXPORT struct diskstats_result *xtra_diskstats_get (
|
|||||||
{
|
{
|
||||||
struct diskstats_result *r = procps_diskstats_get(info, name, actual_enum);
|
struct diskstats_result *r = procps_diskstats_get(info, name, actual_enum);
|
||||||
|
|
||||||
|
if (actual_enum < 0 || actual_enum >= DISKSTATS_logical_end) {
|
||||||
|
fprintf(stderr, "%s line %d: invalid item = %d, type = %s\n"
|
||||||
|
, file, lineno, actual_enum, typestr);
|
||||||
|
}
|
||||||
if (r) {
|
if (r) {
|
||||||
char *str = Item_table[r->item].type2str;
|
char *str = Item_table[r->item].type2str;
|
||||||
if (str[0]
|
if (str[0]
|
||||||
|
@ -89,8 +89,9 @@ struct diskstats_reap {
|
|||||||
#define DISKSTATS_TYPE_DISK -11111
|
#define DISKSTATS_TYPE_DISK -11111
|
||||||
#define DISKSTATS_TYPE_PARTITION -22222
|
#define DISKSTATS_TYPE_PARTITION -22222
|
||||||
|
|
||||||
#define DISKSTATS_GET( info, name, actual_enum, type ) \
|
#define DISKSTATS_GET( info, name, actual_enum, type ) ( { \
|
||||||
procps_diskstats_get( info, name, actual_enum ) -> result . type
|
struct diskstats_result *r = procps_diskstats_get( info, actual_enum ); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
|
|
||||||
#define DISKSTATS_VAL( relative_enum, type, stack, info ) \
|
#define DISKSTATS_VAL( relative_enum, type, stack, info ) \
|
||||||
stack -> head [ relative_enum ] . result . type
|
stack -> head [ relative_enum ] . result . type
|
||||||
|
@ -872,6 +872,10 @@ PROCPS_EXPORT struct meminfo_result *xtra_meminfo_get (
|
|||||||
{
|
{
|
||||||
struct meminfo_result *r = procps_meminfo_get(info, actual_enum);
|
struct meminfo_result *r = procps_meminfo_get(info, actual_enum);
|
||||||
|
|
||||||
|
if (actual_enum < 0 || actual_enum >= MEMINFO_logical_end) {
|
||||||
|
fprintf(stderr, "%s line %d: invalid item = %d, type = %s\n"
|
||||||
|
, file, lineno, actual_enum, typestr);
|
||||||
|
}
|
||||||
if (r) {
|
if (r) {
|
||||||
char *str = Item_table[r->item].type2str;
|
char *str = Item_table[r->item].type2str;
|
||||||
if (str[0]
|
if (str[0]
|
||||||
|
@ -137,8 +137,9 @@ struct meminfo_stack {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define MEMINFO_GET( info, actual_enum, type ) \
|
#define MEMINFO_GET( info, actual_enum, type ) ( { \
|
||||||
procps_meminfo_get( info, actual_enum ) -> result . type
|
struct meminfo_result *r = procps_meminfo_get( info, actual_enum ); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
|
|
||||||
#define MEMINFO_VAL( relative_enum, type, stack, info ) \
|
#define MEMINFO_VAL( relative_enum, type, stack, info ) \
|
||||||
stack -> head [ relative_enum ] . result . type
|
stack -> head [ relative_enum ] . result . type
|
||||||
|
@ -1029,6 +1029,10 @@ PROCPS_EXPORT struct slabinfo_result *xtra_slabinfo_get (
|
|||||||
{
|
{
|
||||||
struct slabinfo_result *r = procps_slabinfo_get(info, actual_enum);
|
struct slabinfo_result *r = procps_slabinfo_get(info, actual_enum);
|
||||||
|
|
||||||
|
if (actual_enum < 0 || actual_enum >= SLABINFO_logical_end) {
|
||||||
|
fprintf(stderr, "%s line %d: invalid item = %d, type = %s\n"
|
||||||
|
, file, lineno, actual_enum, typestr);
|
||||||
|
}
|
||||||
if (r) {
|
if (r) {
|
||||||
char *str = Item_table[r->item].type2str;
|
char *str = Item_table[r->item].type2str;
|
||||||
if (str[0]
|
if (str[0]
|
||||||
|
@ -95,8 +95,9 @@ struct slabinfo_reap {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define SLABINFO_GET( info, actual_enum, type ) \
|
#define SLABINFO_GET( info, actual_enum, type ) ( { \
|
||||||
procps_slabinfo_get( info, actual_enum ) -> result . type
|
struct slabinfo_result *r = procps_slabinfo_get( info, actual_enum ); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
|
|
||||||
#define SLABINFO_VAL( relative_enum, type, stack, info ) \
|
#define SLABINFO_VAL( relative_enum, type, stack, info ) \
|
||||||
stack -> head [ relative_enum ] . result . type
|
stack -> head [ relative_enum ] . result . type
|
||||||
|
@ -1147,6 +1147,10 @@ PROCPS_EXPORT struct stat_result *xtra_stat_get (
|
|||||||
{
|
{
|
||||||
struct stat_result *r = procps_stat_get(info, actual_enum);
|
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) {
|
if (r) {
|
||||||
char *str = Item_table[r->item].type2str;
|
char *str = Item_table[r->item].type2str;
|
||||||
if (str[0]
|
if (str[0]
|
||||||
|
@ -105,8 +105,9 @@ struct stat_reaped {
|
|||||||
#define STAT_SUMMARY_ID -11111
|
#define STAT_SUMMARY_ID -11111
|
||||||
#define STAT_NODE_INVALID -22222
|
#define STAT_NODE_INVALID -22222
|
||||||
|
|
||||||
#define STAT_GET( info, actual_enum, type ) \
|
#define STAT_GET( info, actual_enum, type ) ( { \
|
||||||
procps_stat_get( info, actual_enum ) -> result . type
|
struct stat_result *r = procps_stat_get( info, actual_enum ); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
|
|
||||||
#define STAT_VAL( relative_enum, type, stack, info ) \
|
#define STAT_VAL( relative_enum, type, stack, info ) \
|
||||||
stack -> head [ relative_enum ] . result . type
|
stack -> head [ relative_enum ] . result . type
|
||||||
|
@ -1268,6 +1268,10 @@ PROCPS_EXPORT struct vmstat_result *xtra_vmstat_get (
|
|||||||
{
|
{
|
||||||
struct vmstat_result *r = procps_vmstat_get(info, actual_enum);
|
struct vmstat_result *r = procps_vmstat_get(info, actual_enum);
|
||||||
|
|
||||||
|
if (actual_enum < 0 || actual_enum >= VMSTAT_logical_end) {
|
||||||
|
fprintf(stderr, "%s line %d: invalid item = %d, type = %s\n"
|
||||||
|
, file, lineno, actual_enum, typestr);
|
||||||
|
}
|
||||||
if (r) {
|
if (r) {
|
||||||
char *str = Item_table[r->item].type2str;
|
char *str = Item_table[r->item].type2str;
|
||||||
if (str[0]
|
if (str[0]
|
||||||
|
@ -285,8 +285,9 @@ struct vmstat_stack {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#define VMSTAT_GET( info, actual_enum, type ) \
|
#define VMSTAT_GET( info, actual_enum, type ) ( { \
|
||||||
procps_vmstat_get( info, actual_enum ) -> result . type
|
struct vmstat_result *r = procps_vmstat_get( info, actual_enum ); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
|
|
||||||
#define VMSTAT_VAL( relative_enum, type, stack, info ) \
|
#define VMSTAT_VAL( relative_enum, type, stack, info ) \
|
||||||
stack -> head [ relative_enum ] . result . type
|
stack -> head [ relative_enum ] . result . type
|
||||||
|
@ -35,8 +35,10 @@ struct diskstats_result *xtra_diskstats_get (
|
|||||||
const char *file,
|
const char *file,
|
||||||
int lineno);
|
int lineno);
|
||||||
|
|
||||||
#define DISKSTATS_GET( info, name, actual_enum, type ) \
|
#define DISKSTATS_GET( info, name, actual_enum, type ) ( { \
|
||||||
xtra_diskstats_get(info, name, actual_enum , STRINGIFY(type), __FILE__, __LINE__) -> result . type; } )
|
struct diskstats_result *r; \
|
||||||
|
r = xtra_diskstats_get(info, name, actual_enum , STRINGIFY(type), __FILE__, __LINE__); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
#endif // . . . . . . . . . .
|
#endif // . . . . . . . . . .
|
||||||
|
|
||||||
#ifdef DISKSTATS_VAL
|
#ifdef DISKSTATS_VAL
|
||||||
@ -66,7 +68,9 @@ struct meminfo_result *xtra_meminfo_get (
|
|||||||
int lineno);
|
int lineno);
|
||||||
|
|
||||||
#define MEMINFO_GET( info, actual_enum, type ) ( { \
|
#define MEMINFO_GET( info, actual_enum, type ) ( { \
|
||||||
xtra_meminfo_get(info, actual_enum , STRINGIFY(type), __FILE__, __LINE__) -> result . type; } )
|
struct meminfo_result *r; \
|
||||||
|
r = xtra_meminfo_get(info, actual_enum , STRINGIFY(type), __FILE__, __LINE__); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
#endif // . . . . . . . . . .
|
#endif // . . . . . . . . . .
|
||||||
|
|
||||||
#ifdef MEMINFO_VAL
|
#ifdef MEMINFO_VAL
|
||||||
@ -112,8 +116,10 @@ struct slabinfo_result *xtra_slabinfo_get (
|
|||||||
const char *file,
|
const char *file,
|
||||||
int lineno);
|
int lineno);
|
||||||
|
|
||||||
#define SLABINFO_GET( info, actual_enum, type ) \
|
#define SLABINFO_GET( info, actual_enum, type ) ( { \
|
||||||
xtra_slabinfo_get(info, actual_enum , STRINGIFY(type), __FILE__, __LINE__) -> result . type; } )
|
struct slabinfo_result *r; \
|
||||||
|
r = xtra_slabinfo_get(info, actual_enum , STRINGIFY(type), __FILE__, __LINE__); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
#endif // . . . . . . . . . .
|
#endif // . . . . . . . . . .
|
||||||
|
|
||||||
#ifdef SLABINFO_VAL
|
#ifdef SLABINFO_VAL
|
||||||
@ -143,7 +149,9 @@ struct stat_result *xtra_stat_get (
|
|||||||
int lineno);
|
int lineno);
|
||||||
|
|
||||||
#define STAT_GET( info, actual_enum, type ) ( { \
|
#define STAT_GET( info, actual_enum, type ) ( { \
|
||||||
xtra_stat_get(info, actual_enum , STRINGIFY(type), __FILE__, __LINE__) -> result . type; } )
|
struct stat_result *r; \
|
||||||
|
r = xtra_stat_get(info, actual_enum , STRINGIFY(type), __FILE__, __LINE__); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
#endif // . . . . . . . . . .
|
#endif // . . . . . . . . . .
|
||||||
|
|
||||||
#ifdef STAT_VAL
|
#ifdef STAT_VAL
|
||||||
@ -173,7 +181,9 @@ struct vmstat_result *xtra_vmstat_get (
|
|||||||
int lineno);
|
int lineno);
|
||||||
|
|
||||||
#define VMSTAT_GET( info, actual_enum, type ) ( { \
|
#define VMSTAT_GET( info, actual_enum, type ) ( { \
|
||||||
xtra_vmstat_get(info, actual_enum , STRINGIFY(type), __FILE__, __LINE__) -> result . type; } )
|
struct vmstat_result *r; \
|
||||||
|
r = xtra_vmstat_get(info, actual_enum , STRINGIFY(type), __FILE__, __LINE__); \
|
||||||
|
r ? r->result . type : 0; } )
|
||||||
#endif // . . . . . . . . . .
|
#endif // . . . . . . . . . .
|
||||||
|
|
||||||
#ifdef VMSTAT_VAL
|
#ifdef VMSTAT_VAL
|
||||||
|
Loading…
Reference in New Issue
Block a user