Fixed core dumps when closing unintialized mongo or sqlite log instances

Fixed a Host header bug in sinqhttpopt
This commit is contained in:
2016-04-08 11:24:02 +02:00
parent 1087dd6c8d
commit 1fb85ef6b5
4 changed files with 16 additions and 11 deletions

View File

@ -29,9 +29,11 @@ static void MongoCallback(unsigned int severity, const char *timeStamp,
static void MongoClose(void *data) static void MongoClose(void *data)
{ {
RemoveLogCallback(MongoCallback); RemoveLogCallback(MongoCallback);
mongoc_collection_destroy (collection); if(collection != NULL){
mongoc_client_destroy (client); mongoc_collection_destroy (collection);
mongoc_cleanup (); mongoc_client_destroy (client);
mongoc_cleanup ();
}
client = NULL; client = NULL;
collection = NULL; collection = NULL;
} }
@ -155,7 +157,7 @@ static void QueryCallback(const bson_t *doc, void *userData)
bson_iter_find(&iter,"severity"); bson_iter_find(&iter,"severity");
severity = bson_iter_int32(&iter); severity = bson_iter_int32(&iter);
formatSeverity(severity,sevBuf,sizeof(sevBuf)); formatSeverity(severity,sevBuf,sizeof(sevBuf));
DynStringConcat(result,(char *)severity); DynStringConcat(result,(char *)sevBuf);
DynStringConcatChar(result,' '); DynStringConcatChar(result,' ');
bson_iter_find(&iter,"sub"); bson_iter_find(&iter,"sub");
sub = bson_iter_utf8(&iter,&length); sub = bson_iter_utf8(&iter,&length);
@ -182,7 +184,7 @@ static int MongoQueryAction(SConnection * pCon, SicsInterp * pSics,
error = sicslogGetError(); error = sicslogGetError();
SCPrintf(pCon,eError,"Error %s querying mongodb", error); SCPrintf(pCon,eError,"Error %s querying mongodb", error);
} else { } else {
SCPureSockWrite(pCon,GetCharArray(result),eValue); SCPureSockWrite(pCon,GetCharArray(result),eLog);
} }
DeleteDynString(result); DeleteDynString(result);
return 1; return 1;

View File

@ -86,6 +86,7 @@ int sicslogQuery(int argc, char *argv[], ResultCallback_t func, void *userData)
/* /*
parse options parse options
*/ */
optind = 1;
while((c = getopt(argc,argv,"s:l:f:t:i:e:c:")) != -1) { while((c = getopt(argc,argv,"s:l:f:t:i:e:c:")) != -1) {
switch (c){ switch (c){
case 's': case 's':
@ -151,7 +152,7 @@ int sicslogQuery(int argc, char *argv[], ResultCallback_t func, void *userData)
/* /*
build the query build the query
*/ */
snprintf(jsonQuery, sizeof(jsonQuery),"{ \"timestamp\" : {\"$gt\": %ld, \"$lt\": %ld}, \"severity\": {\"$lt\": %d}", snprintf(jsonQuery, sizeof(jsonQuery),"{ \"timestamp\" : {\"$gt\": %ld, \"$lt\": %ld}, \"severity\": {\"$lte\": %d}",
from,to,severity-1); from,to,severity-1);
if(sub != NULL){ if(sub != NULL){
snprintf(subQuery,sizeof(subQuery),", \"sub\" : \"%s\"", sub); snprintf(subQuery,sizeof(subQuery),", \"sub\" : \"%s\"", sub);

View File

@ -168,11 +168,11 @@ static void sendGet(pHttpProt pHttp, char *path)
char buffer[1024]; char buffer[1024];
char hostname[256]; char hostname[256];
gethostname(hostname,255); ANETinfo(pHttp->sockHandle,hostname,sizeof(hostname));
snprintf(buffer,1024,"GET %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n", snprintf(buffer,1024,"GET %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n",
path, hostname); path, hostname);
ANETwrite(pHttp->sockHandle, buffer,strlen(buffer)); ANETwrite(pHttp->sockHandle, buffer,strlen(buffer));
sendAuth(pHttp); sendAuth(pHttp);
} }
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
static void sendPost(pHttpProt pHttp, char *path, char *data) static void sendPost(pHttpProt pHttp, char *path, char *data)
@ -180,7 +180,7 @@ static void sendPost(pHttpProt pHttp, char *path, char *data)
char buffer[1024]; char buffer[1024];
char hostname[256]; char hostname[256];
gethostname(hostname,255); ANETinfo(pHttp->sockHandle,hostname,sizeof(hostname));
snprintf(buffer,1024,"POST %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n", snprintf(buffer,1024,"POST %s HTTP/1.1\r\nHost: %s\r\nConnection: keep-alive\r\n",
path, hostname); path, hostname);
ANETwrite(pHttp->sockHandle, buffer,strlen(buffer)); ANETwrite(pHttp->sockHandle, buffer,strlen(buffer));

View File

@ -13,7 +13,7 @@
#include <sicsutil.h> #include <sicsutil.h>
#include <sics.h> #include <sics.h>
static sqlite3 *db; static sqlite3 *db = NULL;
static char sqliteFile[1024]; static char sqliteFile[1024];
static unsigned int lineCount = 0; static unsigned int lineCount = 0;
static unsigned int sqlActive = 0; static unsigned int sqlActive = 0;
@ -23,7 +23,7 @@ static void SqlFlush(void)
{ {
char *err; char *err;
if(sqlActive == 1){ if(sqlActive == 1 && db != NULL){
sqlite3_exec(db,"END TRANSACTION",NULL,NULL,&err); sqlite3_exec(db,"END TRANSACTION",NULL,NULL,&err);
lineCount = 0; lineCount = 0;
} }
@ -66,10 +66,12 @@ static void SqlClose(void *data)
{ {
char *err; char *err;
if(sqlActive == 1 && db != NULL){
sqlite3_exec(db,"END TRANSACTION",NULL,NULL,&err); sqlite3_exec(db,"END TRANSACTION",NULL,NULL,&err);
sqlite3_close(db); sqlite3_close(db);
RemoveLogCallback(SqliteCallback); RemoveLogCallback(SqliteCallback);
sqlActive = 0; sqlActive = 0;
}
} }
/*------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------*/
static int SQLLogConfigAction(SConnection * pCon, SicsInterp * pSics, static int SQLLogConfigAction(SConnection * pCon, SicsInterp * pSics,