From: Victor Julien Date: Tue, 27 Jan 2015 15:34:16 +0000 (+0100) Subject: detect: no exit on reference/classification errors X-Git-Tag: suricata-2.1beta4~134 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=092ddc1853d4f11baf7d6b64c61e0e3b29044e07;p=thirdparty%2Fsuricata.git detect: no exit on reference/classification errors Don't exit on errors during classification and reference parsing. Add some suppression of error messages when in unittest mode. --- diff --git a/src/util-classification-config.c b/src/util-classification-config.c index 3a0d62a8cb..db79b7a213 100644 --- a/src/util-classification-config.c +++ b/src/util-classification-config.c @@ -97,6 +97,10 @@ int SCClassConfInitContextAndLocalResources(DetectEngineCtx *de_ctx) if (fd == NULL) { filename = SCClassConfGetConfFilename(); if ( (fd = fopen(filename, "r")) == NULL) { +#ifdef UNITTESTS + if (RunmodeIsUnittests()) + goto error; // silently fail +#endif SCLogError(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename, strerror(errno)); goto error; } @@ -206,7 +210,7 @@ static char *SCClassConfStringToLowercase(const char *str) if ( (new_str = SCStrdup(str)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); - exit(EXIT_FAILURE); + return NULL; } temp_str = new_str; @@ -392,13 +396,17 @@ SCClassConfClasstype *SCClassConfAllocClasstype(uint8_t classtype_id, if ( (ct->classtype = SCClassConfStringToLowercase(classtype)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); - exit(EXIT_FAILURE); + + SCClassConfDeAllocClasstype(ct); + return NULL; } if (classtype_desc != NULL && (ct->classtype_desc = SCStrdup(classtype_desc)) == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Error allocating memory"); - exit(EXIT_FAILURE); + + SCClassConfDeAllocClasstype(ct); + return NULL; } ct->classtype_id = classtype_id; @@ -519,8 +527,14 @@ void SCClassConfClasstypeHashFree(void *ch) void SCClassConfLoadClassficationConfigFile(DetectEngineCtx *de_ctx) { if (SCClassConfInitContextAndLocalResources(de_ctx) == -1) { - SCLogInfo("Please check the \"classification-file\" option in your suricata.yaml file"); - exit(EXIT_FAILURE); +#ifdef UNITTESTS + if (RunmodeIsUnittests() && fd == NULL) { + return; + } +#endif + SCLogError(SC_ERR_OPENING_FILE, "please check the \"classification-file\" " + "option in your suricata.yaml file"); + return; } SCClassConfParseFile(de_ctx); diff --git a/src/util-reference-config.c b/src/util-reference-config.c index 1eb8047e05..aea8562772 100644 --- a/src/util-reference-config.c +++ b/src/util-reference-config.c @@ -93,6 +93,10 @@ static int SCRConfInitContextAndLocalResources(DetectEngineCtx *de_ctx) if (fd == NULL) { filename = SCRConfGetConfFilename(); if ((fd = fopen(filename, "r")) == NULL) { +#ifdef UNITTESTS + if (RunmodeIsUnittests()) + goto error; // silently fail +#endif SCLogError(SC_ERR_FOPEN, "Error opening file: \"%s\": %s", filename, strerror(errno)); goto error; @@ -492,8 +496,14 @@ void SCRConfReferenceHashFree(void *data) int SCRConfLoadReferenceConfigFile(DetectEngineCtx *de_ctx) { if (SCRConfInitContextAndLocalResources(de_ctx) == -1) { - SCLogInfo("Please check the \"reference-config-file\" option in your suricata.yaml file"); - exit(EXIT_FAILURE); +#ifdef UNITTESTS + if (RunmodeIsUnittests() && fd == NULL) { + return -1; + } +#endif + SCLogError(SC_ERR_OPENING_FILE, "please check the \"reference-config-file\" " + "option in your suricata.yaml file"); + return -1; } SCRConfParseFile(de_ctx); @@ -518,7 +528,7 @@ SCRConfReference *SCRConfGetReference(const char *rconf_name, { SCRConfReference *ref_conf = SCRConfAllocSCRConfReference(rconf_name, NULL); if (ref_conf == NULL) - exit(EXIT_FAILURE); + return NULL; SCRConfReference *lookup_ref_conf = HashTableLookup(de_ctx->reference_conf_ht, ref_conf, 0);