bug in finding a contact

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
eponymousalias
Posts: 17
Joined: Mon Mar 07, 2016 5:38 am

bug in finding a contact

Post 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.
bheden
Product Development Manager
Posts: 179
Joined: Thu Feb 13, 2014 9:50 am
Location: Nagios Enterprises

Re: bug in finding a contact

Post by bheden »

Can you create a Pull Request on GitHub and I'll merge it in?

Thanks!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Nagios Enterprises
Senior Developer
eponymousalias
Posts: 17
Joined: Mon Mar 07, 2016 5:38 am

Re: bug in finding a contact

Post 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.
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: bug in finding a contact

Post 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!
eponymousalias
Posts: 17
Joined: Mon Mar 07, 2016 5:38 am

Re: bug in finding a contact

Post by eponymousalias »

No, there's nothing more to add.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: bug in finding a contact

Post by tmcdonald »

I'll be closing this thread now, but feel free to open another if you need anything in the future!
Former Nagios employee
Locked