Blame SOURCES/rsyslog-8.24.0-rhbz1684236-omelastic-sigsegv.patch

ff08e8
From 48dd54fd6d1edeb5dcdde95935a3ca9d2a6ab52e Mon Sep 17 00:00:00 2001
ff08e8
From: Rich Megginson <rmeggins@redhat.com>
ff08e8
Date: Wed, 6 Mar 2019 10:23:28 -0700
ff08e8
Subject: [PATCH] Bug 1684236 - rsyslog-8.24.0-34.el7.x86_64 SIGSEGV when using
ff08e8
 rsyslog-elasticsearch-8.24.0-34
ff08e8
ff08e8
https://bugzilla.redhat.com/show_bug.cgi?id=1684236
ff08e8
ff08e8
Cause: When omelasticsearch has a problem sending data to
ff08e8
Elasticsearch because the connection was broken, the curl api
ff08e8
returns an error code that was not being checked.  The
ff08e8
omelasticsearch code also assumed that the reply field would
ff08e8
always be allocated, but it is not in this error case.
ff08e8
ff08e8
Consequence: rsyslog crashes when the connection to Elasticsearch
ff08e8
is lost while attempting to send data to Elasticsearch.
ff08e8
ff08e8
Fix: Check for the correct error code (CURLE_GOT_NOTHING), and
ff08e8
also check that the reply field was allocated.
ff08e8
ff08e8
Result: rsyslog does not crash when the connection to Elasticsearch
ff08e8
is lost while attempting to send data to Elasticsearch.
ff08e8
---
ff08e8
 plugins/omelasticsearch/omelasticsearch.c | 12 +++++++++---
ff08e8
 1 file changed, 9 insertions(+), 3 deletions(-)
ff08e8
ff08e8
diff --git a/plugins/omelasticsearch/omelasticsearch.c b/plugins/omelasticsearch/omelasticsearch.c
ff08e8
index 248a369d2..d0c3f91d5 100644
ff08e8
--- a/plugins/omelasticsearch/omelasticsearch.c
ff08e8
+++ b/plugins/omelasticsearch/omelasticsearch.c
ff08e8
@@ -1431,6 +1431,7 @@ curlPost(wrkrInstanceData_t *pWrkrData, uchar *message, int msglen, uchar **tpls
ff08e8
 	    || code == CURLE_COULDNT_RESOLVE_PROXY
ff08e8
 	    || code == CURLE_COULDNT_CONNECT
ff08e8
 	    || code == CURLE_WRITE_ERROR
ff08e8
+	    || code == CURLE_GOT_NOTHING
ff08e8
 	   ) {
ff08e8
 		STATSCOUNTER_INC(indexHTTPReqFail, mutIndexHTTPReqFail);
ff08e8
 		indexHTTPFail += nmsgs;
ff08e8
@@ -1441,15 +1442,20 @@ curlPost(wrkrInstanceData_t *pWrkrData, uchar *message, int msglen, uchar **tpls
ff08e8
 	}
ff08e8
 
ff08e8
 	DBGPRINTF("omelasticsearch: pWrkrData replyLen = '%d'\n", pWrkrData->replyLen);
ff08e8
-	if(pWrkrData->replyLen > 0) {
ff08e8
+	if(NULL != pWrkrData->reply) {
ff08e8
+	    if(pWrkrData->replyLen > 0) {
ff08e8
 		pWrkrData->reply[pWrkrData->replyLen] = '\0'; /* Append 0 Byte if replyLen is above 0 - byte has been reserved in malloc */
ff08e8
+	    }
ff08e8
+	    CHKiRet(checkResult(pWrkrData, message));
ff08e8
+	    DBGPRINTF("omelasticsearch: pWrkrData reply: '%s'\n", pWrkrData->reply);
ff08e8
+	} else {
ff08e8
+	    DBGPRINTF("omelasticsearch: pWrkrData reply is NULL\n");
ff08e8
 	}
ff08e8
-	DBGPRINTF("omelasticsearch: pWrkrData reply: '%s'\n", pWrkrData->reply);
ff08e8
 
ff08e8
-	CHKiRet(checkResult(pWrkrData, message));
ff08e8
 finalize_it:
ff08e8
 	incrementServerIndex(pWrkrData);
ff08e8
 	free(pWrkrData->reply);
ff08e8
+	pWrkrData->reply = NULL;
ff08e8
 	RETiRet;
ff08e8
 }
ff08e8
 
ff08e8
-- 
ff08e8
2.20.1
ff08e8