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

check_http expects >0 response headers

Fix for issue https://github.com/nagios-plugins/nagios-plugins/issues/42

If a server just returns the `HTTP/1.0 200 OK` and a body without
any headers at all, the body ended up in the `header` variable.
Fixed so it's checking using proper protocol.
John C. Frickson 9 лет назад
Родитель
Сommit
224b1e50e7
1 измененных файлов с 7 добавлено и 3 удалено
  1. 7 3
      plugins/check_http.c

+ 7 - 3
plugins/check_http.c

@@ -1192,9 +1192,12 @@ check_http (void)
 
   /* find status line and null-terminate it */
   status_line = page;
-  page += (size_t) strcspn (page, "\r\n");
+  page = strstr(page, "\r\n");
+  page += 2;
+/*  page += (size_t) strcspn (page, "\r\n"); */
+/*  page += (size_t) strspn (page, "\r\n"); */
   pos = page;
-  page += (size_t) strspn (page, "\r\n");
+
   status_line[strcspn(status_line, "\r\n")] = 0;
   strip (status_line);
   if (verbose)
@@ -1202,7 +1205,8 @@ check_http (void)
 
   /* find header info and null-terminate it */
   header = page;
-  while (strcspn (page, "\r\n") > 0) {
+/*  while (strcspn (page, "\r\n") > 0) { */
+  while (page[0] != '\r' || page[1] != '\n') {
     page += (size_t) strcspn (page, "\r\n");
     pos = page;
     if ((strspn (page, "\r") == 1 && strspn (page, "\r\n") >= 2) ||