[Nagiosplug-devel] check_ldap segfault and syntax help patch

andyrew609 at attbi.com andyrew609 at attbi.com
Mon Jan 6 03:02:03 CET 2003


     I've got a patch to improve the syntax help the program gives and to 
(hopefully) fix a segfault.  The current syntax check_ldap prints out doesn't 
make it clear that the -w and -c options are required.  I spent quite a few 
minutes grepping around the source and scratching my head before I figured that 
out :-).
     Also, the program segfaults if is called so that argc>=2, but the -b option 
and -H option are not provided.  This is because the program references elements 
in the array of ld_base and ld_host without checking if these variables are 
defined.  I think this was just a typo, and I fixed it.  Either that or I fixed 
one problem while unintentially breaking something more subtle.  You be the 
judge.

Regards,
Andrew McDavid

diff -u 
--------------------------------------------------------

--- check_ldap.c        Thu Nov 14 17:04:51 2002
+++ check_ldap.c.new    Mon Jan  6 02:15:41 2003
@@ -32,6 +32,7 @@
 #include <ldap.h>

 #define UNKNOWN -1
+#define E_MOREARGS 3

 int process_arguments (int, char **);
 int validate_arguments (void);
@@ -53,10 +54,11 @@

        int t_diff;
        time_t time0, time1;
-
-       if (process_arguments (argc, argv) == ERROR)
+       int state = process_arguments (argc, argv);
+       if (state == ERROR)
                usage ("check_ldap: could not parse arguments\n");
-
+       if (state == E_MOREARGS)
+               usage ("check_ldap: four arguments are required\n");
        /* initialize alarm signal handling */
        signal (SIGALRM, socket_timeout_alarm_handler);

@@ -143,7 +145,7 @@
 #endif

        if (argc < 2)
-               return ERROR;
+               return E_MOREARGS;

        for (c = 1; c < argc; c++) {
                if (strcmp ("-to", argv[c]) == 0)
@@ -212,10 +214,10 @@
 int
 validate_arguments ()
 {
-       if (ld_host[0] == 0 ||
-                       ld_base[0] == 0 ||
+       if (ld_host == 0 ||
+                       ld_base == 0 ||
                        ld_port == UNKNOWN || warn_time == UNKNOWN || crit_time 
== UNKNOWN) {
-               return ERROR;
+               return E_MOREARGS;
        }
        else {
                return OK;
@@ -241,7 +243,7 @@
                 "\t-b [--base] ... ldap base (eg. ou=my unit, o=my org, 
c=at)\n"
                 "\t-D [--bind] ... ldap bind DN (if required)\n"
                 "\t-P [--pass] ... ldap password (if required)\n"
-                "\t-p [--port] ... ldap port (normaly 389)\n"
+                "\t-p [--port] ... ldap port (defaults to 389)\n"
                 "\t-w [--warn] ... time in secs. - if the exceeds <warn> the 
STATE_WARNING will be returned\n"
                 "\t-c [--crit] ... time in secs. - if the exceeds <crit> the 
STATE_CRITICAL will be returned\n"
                 "\n");
@@ -252,7 +254,7 @@
 print_usage ()
 {
        printf
-               ("Usage: %s -H <host> -b <base_dn> -p <port> [-a <attr>] [-D 
<binddn>]\n"
-                "         [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t 
timeout]\n"
+       ("Usage: %s -H <host> -b <base_dn>  -w <warn_time> -c <crit_time>\n"
+        "[-p <port>] [-a <attr>] [-D <binddn>] [-P <password>] [-t time out]\n"
                 "(Note: all times are in seconds.)\n", PROGNAME);
 }




More information about the Devel mailing list