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/utils.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/utils.c')
| -rw-r--r-- | plugins/utils.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/plugins/utils.c b/plugins/utils.c index ee620133..348ec022 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
| @@ -678,3 +678,19 @@ char *sperfdata_int (const char *label, | |||
| 678 | 678 | ||
| 679 | return data; | 679 | return data; |
| 680 | } | 680 | } |
| 681 | |||
| 682 | int | ||
| 683 | open_max (void) | ||
| 684 | { | ||
| 685 | errno = 0; | ||
| 686 | if (maxfd > 0) | ||
| 687 | return(maxfd); | ||
| 688 | |||
| 689 | if ((maxfd = sysconf (_SC_OPEN_MAX)) < 0) { | ||
| 690 | if (errno == 0) | ||
| 691 | maxfd = DEFAULT_MAXFD; /* it's indeterminate */ | ||
| 692 | else | ||
| 693 | die (STATE_UNKNOWN, _("sysconf error for _SC_OPEN_MAX\n")); | ||
| 694 | } | ||
| 695 | return(maxfd); | ||
| 696 | } | ||
