Code

check_tcp was returning uninitialized string with user-defined refused outcome
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>
Mon, 1 Mar 2004 12:27:19 +0000 (12:27 +0000)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>
Mon, 1 Mar 2004 12:27:19 +0000 (12:27 +0000)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@833 f882894a-f735-0410-b71e-b25c423dba1c

plugins/check_tcp.c
plugins/netutils.c

index 7bd48d1aa058d7e50702d503d9e45e207d722c94..55ce89848215e082f7fc35e406008311f41ef0db 100644 (file)
@@ -206,6 +206,7 @@ main (int argc, char **argv)
        server_port = PORT;
        server_send = SEND;
        server_quit = QUIT;
+       status = strdup ("");
 
        if (process_arguments (argc, argv) == ERROR)
                usage (_("Could not parse arguments\n"));
@@ -259,7 +260,6 @@ main (int argc, char **argv)
 
                buffer = malloc (MAXBUF);
                memset (buffer, '\0', MAXBUF);
-               status = strdup ("");
                /* watch for the expect string */
                while ((i = my_recv ()) > 0) {
                        buffer[i] = '\0';
@@ -271,7 +271,7 @@ main (int argc, char **argv)
                }
 
                /* return a CRITICAL status if we couldn't read any data */
-               if (status == NULL)
+               if (strlen(status) == 0)
                        die (STATE_CRITICAL, _("No data received from host\n"));
 
                strip (status);
index 5017eb9e9651fe754aadc4473b7cd82b213d8bdb..1fa69a358f86101d063a494f685102dbeb4e9955 100644 (file)
@@ -252,11 +252,7 @@ my_connect (const char *host_name, int port, int *sd, int proto)
                        if (result < 0) {
                                switch (errno) {
                                case ECONNREFUSED:
-                                       switch (econn_refuse_state) {
-                                       case STATE_OK:
-                                       case STATE_WARNING:
-                                               was_refused = TRUE;
-                                       }
+                                       was_refused = TRUE;
                                        break;
                                }
                        }
@@ -269,8 +265,21 @@ my_connect (const char *host_name, int port, int *sd, int proto)
 
        if (result == 0)
                return STATE_OK;
-       else if (was_refused)
-               return econn_refuse_state;
+       else if (was_refused) {
+               switch (econn_refuse_state) { /* a user-defined expected outcome */
+               case STATE_OK:       
+               case STATE_WARNING:  /* user wants WARN or OK on refusal */
+                       return econn_refuse_state;
+                       break;
+               case STATE_CRITICAL: /* user did not set econn_refuse_state */
+                       printf ("%s\n", strerror(errno));
+                       return econn_refuse_state;
+                       break;
+               default: /* it's a logic error if we do not end up in STATE_(OK|WARNING|CRITICAL) */
+                       return STATE_UNKNOWN;
+                       break;
+               }
+       }
        else {
                printf ("%s\n", strerror(errno));
                return STATE_CRITICAL;