Pārlūkot izejas kodu

Fix the memory allocation for the thresholds data

Allocate the appropriate amount of memory for storing the thresholds
data.  Before, we allocated the amount of memory required for storing a
_pointer_ to the thresholds data.  This crashed (at least) check_mysql
when using its "-S" option on FreeBSD/amd64 (as reported and analyzed by
Nikita Kalabukhov - 2797757).

Signed-off-by: Holger Weiss <holger@zedat.fu-berlin.de>
Holger Weiss 17 gadi atpakaļ
vecāks
revīzija
9eabd8d054
2 mainītis faili ar 4 papildinājumiem un 1 dzēšanām
  1. 1 0
      THANKS.in
  2. 3 1
      lib/utils_base.c

+ 1 - 0
THANKS.in

@@ -254,3 +254,4 @@ Ben Timby
 Martin Foster
 Joe Presbrey
 Will Preston
+Nikita Kalabukhov

+ 3 - 1
lib/utils_base.c

@@ -101,7 +101,9 @@ _set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_st
 {
 	thresholds *temp_thresholds = NULL;
 
-	temp_thresholds = malloc(sizeof(temp_thresholds));
+	if ((temp_thresholds = malloc(sizeof(thresholds))) == NULL)
+		die(STATE_UNKNOWN, _("Cannot allocate memory: %s\n"),
+		    strerror(errno));
 
 	temp_thresholds->warning = NULL;
 	temp_thresholds->critical = NULL;