summaryrefslogtreecommitdiffstats
path: root/plugins/check_dns.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_dns.c')
-rw-r--r--plugins/check_dns.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 2765f64..f1071d8 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -139,12 +139,16 @@ main (int argc, char **argv)
139 /* Strip leading spaces */ 139 /* Strip leading spaces */
140 for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) 140 for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++)
141 /* NOOP */; 141 /* NOOP */;
142 address = strscpy (address, temp_buffer); 142 address = strdup (temp_buffer);
143 strip (address); 143 strip (address);
144 if (address==NULL || strlen(address)==0)
145 terminate (STATE_CRITICAL,
146 "DNS CRITICAL - '%s' returned empty host name string\n",
147 NSLOOKUP_COMMAND);
144 result = STATE_OK; 148 result = STATE_OK;
145 } 149 }
146 else { 150 else {
147 output = strscpy (output, "Unknown error (plugin)"); 151 output = strdup ("Unknown error (plugin)");
148 result = STATE_WARNING; 152 result = STATE_WARNING;
149 } 153 }
150 154
@@ -179,11 +183,18 @@ main (int argc, char **argv)
179 output = strscpy (output, "nslookup returned error status"); 183 output = strscpy (output, "nslookup returned error status");
180 } 184 }
181 185
186 /* If we got here, we should have an address string,
187 and we can segfault if we do not */
188 if (address==NULL || strlen(address)==0)
189 terminate (STATE_CRITICAL,
190 "DNS CRITICAL - '%s' output parsing exited with no address\n",
191 NSLOOKUP_COMMAND);
192
182 /* compare to expected address */ 193 /* compare to expected address */
183 if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) { 194 if (result == STATE_OK && match_expected_address && strcmp(address, expected_address)) {
184 result = STATE_CRITICAL; 195 result = STATE_CRITICAL;
185 asprintf(&output, "expected %s but got %s", expected_address, address); 196 asprintf(&output, "expected %s but got %s", expected_address, address);
186 } 197 }
187 198
188 elapsed_time = delta_time (tv); 199 elapsed_time = delta_time (tv);
189 200