Page 1 of 1

bug in finding a contact

Posted: Tue Jun 27, 2017 11:11 pm
by eponymousalias
The following bug (with the fix shown here) appears
in the find_contact_by_name_or_alias() routine in
Nagios 4.3.2 and various earlier releases:

Code: Select all

nagios-4.3.2/base % diff -u notifications.c.orig notifications.c
--- notifications.c.orig        2017-05-09 10:03:31.000000000 -0700
+++ notifications.c     2017-06-27 20:41:48.332519925 -0700
@@ -36,7 +36,7 @@
 {
        contact *c = NULL; 
 
-       if (!name || !(c = find_contact(name)))
+       if (!name || (c = find_contact(name)))
                return c;
        for (c = contact_list; c; c = c->next)
                if (!strcmp(c->alias, name))
With the present code, the contact is pretty much guaranteed not to
be found. If the correct contact name is given, it will be ignored.
And the alias is not likely to be identical to the name, so that will
be ignored as well. The corrected code recognizes when find_contact()
has found the desired contact, and returns that result.

I don't know how much of a difference fixing this will make, considering
for instance that on line 958 of base/checks.c, the service_notification()
routine is called with a NULL third parameter (for the not_author
argument of that routine). But perhaps there are other calls where it
might matter, or perhaps (I haven't checked any of this) that call might
now be modified to specify some particular author for the notification.

Re: bug in finding a contact

Posted: Wed Jun 28, 2017 12:58 pm
by bheden
Can you create a Pull Request on GitHub and I'll merge it in?

Thanks!

Re: bug in finding a contact

Posted: Thu Jun 29, 2017 5:08 pm
by eponymousalias
I'm not a github guy, so I won't do a pull request. But it's just a one-character change (eliminate a single bang character); you can handle that easily enough.

More important is testing the change, to prove that it's worthwhile and that it actually changes the existing behavior as desired. I forgot to mention in the original post where the effect of this bug shows up. If the contact cannot be found, the $NOTIFICATIONAUTHORNAME$ and $NOTIFICATIONAUTHORALIAS$ macros do not get expanded when they should be. We've seen that happen in particular during an acknowledgement notification. So this bug does have an externally observable effect.

Re: bug in finding a contact

Posted: Fri Jun 30, 2017 11:53 am
by dwhitfield
The developers are aware of the issue. Did you have anything else you wanted to add, or should I go ahead and lock the thread?

Thanks again for posting the fix!

Re: bug in finding a contact

Posted: Fri Jun 30, 2017 9:14 pm
by eponymousalias
No, there's nothing more to add.

Re: bug in finding a contact

Posted: Wed Jul 05, 2017 9:42 am
by tmcdonald
I'll be closing this thread now, but feel free to open another if you need anything in the future!