diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-23 15:07:33 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2003-08-23 15:07:33 +0000 |
commit | 1db3424e5f6b0b8cfbf41a287fe48296931be72b (patch) | |
tree | 461467e7ee313044970fe5ce4876f8499b027b1c /plugins | |
parent | 8d978764d17a8472b89a4f47587dc259db39c5f8 (diff) | |
download | monitoring-plugins-1db3424e5f6b0b8cfbf41a287fe48296931be72b.tar.gz |
- found and fixed memory allocation error in rewritten redir() function
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@695 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_http.c | 112 |
1 files changed, 54 insertions, 58 deletions
diff --git a/plugins/check_http.c b/plugins/check_http.c index 6b952c37..cffe810f 100644 --- a/plugins/check_http.c +++ b/plugins/check_http.c | |||
@@ -475,9 +475,6 @@ check_http (void) | |||
475 | int sslerr; | 475 | int sslerr; |
476 | #endif | 476 | #endif |
477 | 477 | ||
478 | if (verbose) | ||
479 | printf ("%s://%s:%d%s [%s]\n", server_type, server_address, server_port, server_url, host_name); | ||
480 | |||
481 | /* try to connect to the host at the given port number */ | 478 | /* try to connect to the host at the given port number */ |
482 | #ifdef HAVE_SSL | 479 | #ifdef HAVE_SSL |
483 | if (use_ssl == TRUE) { | 480 | if (use_ssl == TRUE) { |
@@ -515,9 +512,6 @@ check_http (void) | |||
515 | asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); | 512 | asprintf (&buf, "%sAuthorization: Basic %s\r\n", buf, auth); |
516 | } | 513 | } |
517 | 514 | ||
518 | if (verbose) | ||
519 | printf ("%s://%s:%d%s\n", server_type, server_address, server_port, server_url); | ||
520 | |||
521 | /* either send http POST data */ | 515 | /* either send http POST data */ |
522 | if (http_post_data) { | 516 | if (http_post_data) { |
523 | asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); | 517 | asprintf (&buf, "%sContent-Type: application/x-www-form-urlencoded\r\n", buf); |
@@ -787,69 +781,71 @@ redir (char *pos, char *status_line) | |||
787 | 781 | ||
788 | while (pos) { | 782 | while (pos) { |
789 | 783 | ||
790 | if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) > 0) { | 784 | if (sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i) < 1) { |
791 | |||
792 | pos += i; | ||
793 | pos += strspn (pos, " \t\r\n"); | ||
794 | 785 | ||
795 | /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ | 786 | pos += (size_t) strcspn (pos, "\r\n"); |
796 | if (sscanf (pos, HD1, type, addr, port, url) == 4) { | 787 | pos += (size_t) strspn (pos, "\r\n"); |
797 | use_ssl = server_type_check (type); | 788 | if (strlen(pos) == 0) |
798 | i = atoi (port); | 789 | die (STATE_UNKNOWN, |
799 | } | 790 | _("UNKNOWN - Could not find redirect location - %s%s\n"), |
800 | 791 | status_line, (display_html ? "</A>" : "")); | |
801 | /* URI_HTTP URI_HOST URI_PATH */ | 792 | continue; |
802 | else if (sscanf (pos, HD2, type, addr, url) == 3 ) { | 793 | } |
803 | use_ssl = server_type_check (type); | ||
804 | i = server_port_check (use_ssl); | ||
805 | } | ||
806 | 794 | ||
807 | /* URI_HTTP URI_HOST URI_PORT */ | 795 | pos += i; |
808 | else if(sscanf (pos, HD3, type, addr, port) == 3) { | 796 | pos += strspn (pos, " \t\r\n"); |
809 | strcpy (url, HTTP_URL); | ||
810 | use_ssl = server_type_check (type); | ||
811 | i = atoi (port); | ||
812 | } | ||
813 | 797 | ||
814 | /* URI_HTTP URI_HOST */ | 798 | url = realloc (url, strcspn (pos, "\r\n")); |
815 | else if(sscanf (pos, HD4, type, addr) == 2) { | 799 | if (url == NULL) |
816 | strcpy (url, HTTP_URL); | 800 | die (STATE_UNKNOWN, _("ERROR: could not allocate url\n")); |
817 | use_ssl = server_type_check (type); | ||
818 | i = server_port_check (use_ssl); | ||
819 | } | ||
820 | 801 | ||
821 | /* URI_PATH */ | 802 | /* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */ |
822 | else if (sscanf (pos, HD5, url) == 1) { | 803 | if (sscanf (pos, HD1, type, addr, port, url) == 4) { |
823 | /* relative url */ | 804 | use_ssl = server_type_check (type); |
824 | if ((url[0] != '/')) { | 805 | i = atoi (port); |
825 | if ((x = strrchr(url, '/'))) | 806 | } |
826 | *x = '\0'; | ||
827 | asprintf (&server_url, "%s/%s", server_url, url); | ||
828 | } | ||
829 | i = server_port; | ||
830 | strcpy (type, server_type); | ||
831 | strcpy (addr, host_name); | ||
832 | } | ||
833 | 807 | ||
834 | else { | 808 | /* URI_HTTP URI_HOST URI_PATH */ |
835 | die (STATE_UNKNOWN, | 809 | else if (sscanf (pos, HD2, type, addr, url) == 3 ) { |
836 | _("UNKNOWN - Could not parse redirect location - %s%s\n"), | 810 | use_ssl = server_type_check (type); |
837 | pos, (display_html ? "</A>" : "")); | 811 | i = server_port_check (use_ssl); |
838 | } | 812 | } |
839 | 813 | ||
840 | break; | 814 | /* URI_HTTP URI_HOST URI_PORT */ |
815 | else if(sscanf (pos, HD3, type, addr, port) == 3) { | ||
816 | strcpy (url, HTTP_URL); | ||
817 | use_ssl = server_type_check (type); | ||
818 | i = atoi (port); | ||
819 | } | ||
841 | 820 | ||
842 | } else { | 821 | /* URI_HTTP URI_HOST */ |
822 | else if(sscanf (pos, HD4, type, addr) == 2) { | ||
823 | strcpy (url, HTTP_URL); | ||
824 | use_ssl = server_type_check (type); | ||
825 | i = server_port_check (use_ssl); | ||
826 | } | ||
843 | 827 | ||
844 | pos += (size_t) strcspn (pos, "\r\n"); | 828 | /* URI_PATH */ |
845 | pos += (size_t) strspn (pos, "\r\n"); | 829 | else if (sscanf (pos, HD5, url) == 1) { |
846 | if (strlen(pos) == 0) | 830 | /* relative url */ |
847 | die (STATE_UNKNOWN, | 831 | if ((url[0] != '/')) { |
848 | _("UNKNOWN - Could not find redirect location - %s%s\n"), | 832 | if ((x = strrchr(url, '/'))) |
849 | status_line, (display_html ? "</A>" : "")); | 833 | *x = '\0'; |
834 | asprintf (&server_url, "%s/%s", server_url, url); | ||
835 | } | ||
836 | i = server_port; | ||
837 | strcpy (type, server_type); | ||
838 | strcpy (addr, host_name); | ||
839 | } | ||
850 | 840 | ||
841 | else { | ||
842 | die (STATE_UNKNOWN, | ||
843 | _("UNKNOWN - Could not parse redirect location - %s%s\n"), | ||
844 | pos, (display_html ? "</A>" : "")); | ||
851 | } | 845 | } |
852 | 846 | ||
847 | break; | ||
848 | |||
853 | } /* end while (pos) */ | 849 | } /* end while (pos) */ |
854 | 850 | ||
855 | if (++redir_depth > max_depth) | 851 | if (++redir_depth > max_depth) |