Просмотр исходного кода

check_dns: Segfaulting with timeout > 26 sec

Fix for issue #161

`nslookup` has it's own timeout, then it exits with the message
`;; connection timed out; no servers could be reached`.
`check_dns` then tries to parse `stdout` looking for a `:`
character, which it doesn't find, so `msg` gets set to NULL.
Then it tries to print that message and segfaults.
John C. Frickson 9 лет назад
Родитель
Сommit
9c2bce5384
2 измененных файлов с 12 добавлено и 5 удалено
  1. 1 0
      NEWS
  2. 11 5
      plugins/check_dns.c

+ 1 - 0
NEWS

@@ -6,6 +6,7 @@ This file documents the major additions and syntax changes between releases.
 	check_mrtg: Add state to status output
 	check_ping: ping runs 30 times when host is down
 	check_icmp: does not have the -p argument in the help
+	check_dns: Segfaulting with timeout > 26 sec
 
 
 2.1.4 2016-11-17

+ 11 - 5
plugins/check_dns.c

@@ -137,7 +137,7 @@ main (int argc, char **argv)
 
   /* run the command */
   if((np_runcmd(command_line, &chld_out, &chld_err, 0)) != 0) {
-    msg = (char *)_("nslookup returned an error status");
+    msg = strdup(_("nslookup returned an error status"));
     result = STATE_WARNING;
   }
 
@@ -223,7 +223,7 @@ main (int argc, char **argv)
       if ((temp_buffer = strstr(chld_out.line[i], "name = ")))
         addresses[n_addresses++] = strdup(temp_buffer);
       else {
-        msg = (char *)_("Warning plugin error");
+        xasprintf(&msg, "%s %s %s %s", _("Warning plugin error"));
         result = STATE_WARNING;
       }
     }
@@ -238,7 +238,10 @@ main (int argc, char **argv)
         ? tmp : result;
     if (result != STATE_OK) {
       msg = strchr (chld_out.line[i], ':');
-      if(msg) msg++;
+      if(msg)
+			  msg++;
+			else
+			 msg = chld_out.line[i];
       break;
     }
   }
@@ -250,8 +253,11 @@ main (int argc, char **argv)
 
     if (error_scan (chld_err.line[i]) != STATE_OK) {
       result = max_state (result, error_scan (chld_err.line[i]));
-      msg = strchr(input_buffer, ':');
-      if(msg) msg++;
+      msg = strchr(chld_err.line[i], ':');
+      if(msg)
+			  msg++;
+			else
+			  msg = chld_err.line[i];
     }
   }