Patch to solve to core-dumping problems in 4.0.7 & 4.1.0-rc1

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
pen
Posts: 2
Joined: Tue Jun 09, 2015 6:48 am

Patch to solve to core-dumping problems in 4.0.7 & 4.1.0-rc1

Post by pen »

I've been having problems with 4.0.7 and 4.1.0-rc1 coredumping on my every now and then on our Solaris 10/SPARC server. One of the problems was "solved" by disabling the automatic update check but the other one was more elusive. Anyway, after some debugging I found two problems:

The use of %zd in a base/utils.c caused vasprintf() to fail, and thus "buf" was NULL. Changed %zd to %lu and cast the return value from strlen() which solved that (unsigned long should be more than enough for that api_query string without having to use the %zd that isn't available on all platforms. Seems that was the only place in the code that used it)

The other bug was a call to va_start() in cgi/jsonutils.c using the incorrect variable (should have been "format" and not "escaped_format). Patch enclosed below:

Code: Select all

diff -r -u nagios-4.1.0rc1/base/utils.c nagios-4.1.0rc1-IFM/base/utils.c
--- nagios-4.1.0rc1/base/utils.c        Wed Feb 18 14:14:58 2015
+++ nagios-4.1.0rc1-IFM/base/utils.c    Mon Jun  8 14:08:40 2015
@@ -3117,10 +3117,14 @@
                 "POST %s HTTP/1.0\r\nUser-Agent: Nagios/%s\r\n"
                 "Connection: close\r\nHost: %s\r\n"
                 "Content-Type: application/x-www-form-urlencoded\r\n"
-                "Content-Length: %zd\r\n\r\n%s",
+                "Content-Length: %lu\r\n\r\n%s",
                 api_path, PROGRAM_VERSION, api_server,
-                strlen(api_query), api_query);
+                (unsigned long) strlen(api_query), api_query);
 
+       if (buf == NULL) {
+         abort();
+       }
+
        my_tcp_connect(api_server, 80, &sd, 2);
        if(sd > 0) {
                /* send request */
diff -r -u nagios-4.1.0rc1/cgi/jsonutils.c nagios-4.1.0rc1-IFM/cgi/jsonutils.c
--- nagios-4.1.0rc1/cgi/jsonutils.c     Wed Feb 18 14:14:58 2015
+++ nagios-4.1.0rc1-IFM/cgi/jsonutils.c Mon Jun  8 11:16:34 2015
@@ -522,7 +522,7 @@
                escaped_format = format;
                }
        if(NULL != escaped_format) {
-               va_start(a_list, escaped_format);
+               va_start(a_list, format);
                result = vasprintf(&buf, escaped_format, a_list);
                va_end(a_list);
                if(result >= 0) {
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Patch to solve to core-dumping problems in 4.0.7 & 4.1.0

Post by tmcdonald »

Nice! Thanks for the patch!

In order to ensure this gets traction, could you please post this as an issue on our GitHub page?

https://github.com/NagiosEnterprises/nagioscore
Former Nagios employee
pen
Posts: 2
Joined: Tue Jun 09, 2015 6:48 am

Re: Patch to solve to core-dumping problems in 4.0.7 & 4.1.0

Post by pen »

I posted the fix(es) as a Pull Request on Github right after posting this (didn't see the information about until afterwards :-). Dunno if that was the "right" way or not but you'll find it there...

- Peter
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Patch to solve to core-dumping problems in 4.0.7 & 4.1.0

Post by tmcdonald »

Looks good. Posting to the forum will get it on the attention of the support team, but for the devs to look at it and do anything with it GitHub is really the best place for it.

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