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) {