[monitoring-plugins] fixed redirect sticky port handling in redir

Andreas Baumann git at monitoring-plugins.org
Sat May 6 19:40:11 CEST 2017


 Module: monitoring-plugins
 Branch: feature_check_curl
 Commit: 13e7b962954a3cda186dad44f8f46a31b9c8b0d7
 Author: Andreas Baumann <mail at andreasbaumann.cc>
   Date: Sat May  6 19:39:59 2017 +0200
    URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=13e7b96

fixed redirect sticky port handling in redir

---

 .travis.yml          |  3 ++-
 configure.ac         |  1 +
 plugins/check_curl.c | 22 +++++++++++-----------
 3 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 617c415..b8249aa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -20,7 +20,7 @@ matrix:
             name: "monitoring-plugins/monitoring-plugins"
             description: "Monitoring Plugins"
           notification_email: team at monitoring-plugins.org
-          build_command_prepend: tools/setup && ./configure
+          build_command_prepend: tools/setup && ./configure --enable-check-curl
           build_command: make
           branch_pattern: coverity.*
     - compiler: "clang"
@@ -55,6 +55,7 @@ install:
   - sudo apt-get install -qq --no-install-recommends autoconf automake
   - sudo apt-get install -qq --no-install-recommends faketime
   - sudo apt-get install -qq --no-install-recommends libmonitoring-plugin-perl
+  - sudo apt-get install -qq --no-install-recommends libcurl3-gnutls-dev
   # Trusty related dependencies (not yet provided)
   - test "$(dpkg -l | grep -E "mysql-(client|server)-[0-9].[0-9]" | grep -c ^ii)" -gt 0 || sudo apt-get install -qq --no-install-recommends mariadb-client mariadb-server
   # enable ssl apache
diff --git a/configure.ac b/configure.ac
index c56163c..2291c51 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1908,5 +1908,6 @@ ACX_FEATURE([enable],[perl-modules])
 ACX_FEATURE([with],[cgiurl])
 ACX_FEATURE([with],[trusted-path])
 ACX_FEATURE([enable],[libtap])
+ACX_FEATURE([enable],[check-curl])
 ACX_FEATURE([with],[libcurl])
 
diff --git a/plugins/check_curl.c b/plugins/check_curl.c
index 72db27a..3ae1c4d 100644
--- a/plugins/check_curl.c
+++ b/plugins/check_curl.c
@@ -551,7 +551,7 @@ check_http (void)
         CURLINFO_REDIRECT_COUNT: get the number of redirects, print it, maybe a range option here is nice like for expected page size?
       */
     } else {
-      // old style redirection is handled below
+      /* old style redirection is handled below */
     }
   }
 
@@ -1019,6 +1019,8 @@ redir (curlhelp_write_curlbuf* header_buf)
     new_host = strdup (uri_string (uri.hostText, buf, DEFAULT_BUFFER_SIZE));
   }
 
+  /* compose new path */
+  /* TODO: handle fragments and query part of URL */
   new_url = (char *)calloc( 1, DEFAULT_BUFFER_SIZE);
   if (uri.pathHead) {
     const UriPathSegmentA* p = uri.pathHead;
@@ -1038,23 +1040,21 @@ redir (curlhelp_write_curlbuf* header_buf)
 
   /* set new values for redirected request */
 
-  free (host_name);
-  host_name = strndup (new_host, MAX_IPV4_HOSTLENGTH);
-  free(new_host);
-
-  server_port = (unsigned short)new_port;
-
-  /* reset virtual port */
-  virtual_port = server_port;
-
   if (!(followsticky & STICKY_HOST)) {
     free (server_address);
     server_address = strndup (new_host, MAX_IPV4_HOSTLENGTH);
   }
   if (!(followsticky & STICKY_PORT)) {
-    server_port = new_port;
+    server_port = (unsigned short)new_port;
   }
 
+  free (host_name);
+  host_name = strndup (new_host, MAX_IPV4_HOSTLENGTH);
+
+  /* reset virtual port */
+  virtual_port = server_port;
+
+  free(new_host);
   free (server_url);
   server_url = new_url;
 



More information about the Commits mailing list