diff options
author | Sven Nierlein <sven@nierlein.de> | 2019-04-25 13:03:10 +0200 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.org> | 2019-05-24 14:51:10 +0200 |
commit | e8325b39c47e6fbf7c8c1e31f9026870d9520af5 (patch) | |
tree | 1c55421a51808253cbe59348e45bd0cb580354c5 /plugins/runcmd.c | |
parent | 4131f2f268e7d771490ebeadbae50b4f95d69695 (diff) | |
download | monitoring-plugins-e8325b39c47e6fbf7c8c1e31f9026870d9520af5.tar.gz |
fix maxfd being zero
If _SC_OPEN_MAX is available then maxfd was zero initialized and never set to the value from sysconf.
This leads to segfaults with free(): invalid size introduced by commit 7cafb0e84550035fe671662c293122be975065ca.
Signed-off-by: Sven Nierlein <sven@nierlein.de>
Diffstat (limited to 'plugins/runcmd.c')
-rw-r--r-- | plugins/runcmd.c | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/plugins/runcmd.c b/plugins/runcmd.c index c3828678..a7155d27 100644 --- a/plugins/runcmd.c +++ b/plugins/runcmd.c | |||
@@ -86,14 +86,8 @@ extern void die (int, const char *, ...) | |||
86 | * through this api and thus achieve async-safeness throughout the api */ | 86 | * through this api and thus achieve async-safeness throughout the api */ |
87 | void np_runcmd_init(void) | 87 | void np_runcmd_init(void) |
88 | { | 88 | { |
89 | #ifndef maxfd | 89 | if(maxfd == 0) |
90 | if(!maxfd && (maxfd = sysconf(_SC_OPEN_MAX)) < 0) { | 90 | maxfd = open_max(); |
91 | /* possibly log or emit a warning here, since there's no | ||
92 | * guarantee that our guess at maxfd will be adequate */ | ||
93 | maxfd = 256; | ||
94 | } | ||
95 | #endif | ||
96 | |||
97 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); | 91 | if(!np_pids) np_pids = calloc(maxfd, sizeof(pid_t)); |
98 | } | 92 | } |
99 | 93 | ||