]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: no exit on reference/classification errors
authorVictor Julien <victor@inliniac.net>
Tue, 27 Jan 2015 15:34:16 +0000 (16:34 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 19 Mar 2015 08:03:51 +0000 (09:03 +0100)
Don't exit on errors during classification and reference parsing.

Add some suppression of error messages when in unittest mode.

src/util-classification-config.c
src/util-reference-config.c

index 3a0d62a8cb4a87b208ac4ae5af3be11153372d4a..db79b7a21340a3338becc4d00236d8aa2256955c 100644 (file)
@@ -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);
index 1eb8047e055cc4ef0169e3e56db5b658818cd967..aea8562772c659242a0fe83f99a053e51c234638 100644 (file)
@@ -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);