From c1fbb1801229f9afd13abfa96ebf5f20acb3a033 Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Tue, 23 Jul 2013 12:33:33 +0200 Subject: Fixed bugid #464 in elasticsearch output module Added some libcurl options in checkConn to disable the bodyport of the request within this functions. Otherwise libcurl could have created a sigsegv when curl_easy_perform() was called. --- plugins/omelasticsearch/omelasticsearch.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'plugins/omelasticsearch/omelasticsearch.c') diff --git a/plugins/omelasticsearch/omelasticsearch.c b/plugins/omelasticsearch/omelasticsearch.c index cb96fb6b..5c53ba19 100644 --- a/plugins/omelasticsearch/omelasticsearch.c +++ b/plugins/omelasticsearch/omelasticsearch.c @@ -224,6 +224,12 @@ checkConn(instanceData *pData) DBGPRINTF("omelasticsearch: checkConn() curl_easy_init() failed\n"); ABORT_FINALIZE(RS_RET_SUSPENDED); } + /* Bodypart of request not needed, so set curl opt to nobody and httpget, otherwise lib-curl could sigsegv */ + curl_easy_setopt(curl, CURLOPT_HTTPGET, TRUE); + curl_easy_setopt(curl, CURLOPT_NOBODY, TRUE); + /* Only enable for debugging + curl_easy_setopt(curl, CURLOPT_VERBOSE, TRUE); */ + cstr = es_str2cstr(url, NULL); curl_easy_setopt(curl, CURLOPT_URL, cstr); free(cstr); -- cgit v1.2.3 From 030e8360702c2c5e227fa70b257f8b3fd048333b Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 24 Jul 2013 09:50:14 +0200 Subject: Fixed a bug in curlPost related to http://bugzilla.adiscon.com/show_bug.cgi?id=464 A Check was added for replylen before writting the 0 Byte to the end of reply data. --- plugins/omelasticsearch/omelasticsearch.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'plugins/omelasticsearch/omelasticsearch.c') diff --git a/plugins/omelasticsearch/omelasticsearch.c b/plugins/omelasticsearch/omelasticsearch.c index 5c53ba19..b98a7828 100644 --- a/plugins/omelasticsearch/omelasticsearch.c +++ b/plugins/omelasticsearch/omelasticsearch.c @@ -613,8 +613,11 @@ curlPost(instanceData *pData, uchar *message, int msglen, uchar **tpls) break; } - pData->reply[pData->replyLen] = '\0'; /* byte has been reserved in malloc */ - DBGPRINTF("omelasticsearch: es reply: '%s'\n", pData->reply); + DBGPRINTF("omelasticsearch: pData replyLen = '%d'\n", pData->replyLen); + if (pData->replyLen > 0) { + pData->reply[pData->replyLen] = '\0'; /* Append 0 Byte if replyLen is above 0 - byte has been reserved in malloc */ + } + DBGPRINTF("omelasticsearch: pData reply: '%s'\n", pData->reply); CHKiRet(checkResult(pData, message)); finalize_it: -- cgit v1.2.3 From 372c7264a598e72f6b9e8f734c9ea6a4a9427c8b Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Wed, 24 Jul 2013 11:10:01 +0200 Subject: Fixed another issue related to http://bugzilla.adiscon.com/show_bug.cgi?id=464 Added check for empty batch data in endTransaction function. Avoids sending an unneeded curlPost, can happen when elasticsearch is shutdown while sending data to. --- plugins/omelasticsearch/omelasticsearch.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'plugins/omelasticsearch/omelasticsearch.c') diff --git a/plugins/omelasticsearch/omelasticsearch.c b/plugins/omelasticsearch/omelasticsearch.c index b98a7828..aea8e321 100644 --- a/plugins/omelasticsearch/omelasticsearch.c +++ b/plugins/omelasticsearch/omelasticsearch.c @@ -651,12 +651,17 @@ ENDdoAction BEGINendTransaction - char *cstr; + char *cstr = NULL; CODESTARTendTransaction dbgprintf("omelasticsearch: endTransaction init\n"); - cstr = es_str2cstr(pData->batch.data, NULL); - dbgprintf("omelasticsearch: endTransaction, batch: '%s'\n", cstr); - CHKiRet(curlPost(pData, (uchar*) cstr, strlen(cstr), NULL)); + /* End Transaction only if batch data is not empty */ + if (pData->batch.data != NULL ) { + cstr = es_str2cstr(pData->batch.data, NULL); + dbgprintf("omelasticsearch: endTransaction, batch: '%s'\n", cstr); + CHKiRet(curlPost(pData, (uchar*) cstr, strlen(cstr), NULL)); + } + else + dbgprintf("omelasticsearch: endTransaction, pData->batch.data is NULL, nothing to send. \n"); finalize_it: free(cstr); dbgprintf("omelasticsearch: endTransaction done with %d\n", iRet); -- cgit v1.2.3