diff --git a/src/detect-engine.c b/src/detect-engine.c index 222a01ef24..2943a294ad 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -4,6 +4,7 @@ #include "debug.h" #include "detect.h" #include "flow.h" +#include "conf.h" #include "detect-parse.h" #include "detect-engine-sigorder.h" @@ -21,6 +22,7 @@ //#include "util-mpm.h" #include "util-hash.h" +#include "util-debug.h" #include "util-var-name.h" #include "tm-modules.h" @@ -35,6 +37,10 @@ DetectEngineCtx *DetectEngineCtxInit(void) { memset(de_ctx,0,sizeof(DetectEngineCtx)); + if (ConfGetBool("engine.init_failure_fatal", &(de_ctx->failure_fatal)) != 1) { + SCLogDebug("ConfGetBool could not load the value."); + } + de_ctx->mpm_matcher = PatternMatchDefaultMatcher(); SigGroupHeadHashInit(de_ctx); diff --git a/src/detect-parse.c b/src/detect-parse.c index ad1ca26cc1..77ac2101ed 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -601,6 +601,10 @@ Signature *SigInit(DetectEngineCtx *de_ctx, char *sigstr) { error: SigFree(sig); + if (de_ctx->failure_fatal == 1) { + fprintf(stderr, "ERROR: Signature init failed.\n"); + exit(EXIT_FAILURE); + } return NULL; } diff --git a/src/detect.h b/src/detect.h index d5f04bd057..ea4e936165 100644 --- a/src/detect.h +++ b/src/detect.h @@ -222,6 +222,7 @@ typedef struct DetectEngineLookupDsize_ { /** \brief main detection engine ctx */ typedef struct DetectEngineCtx_ { uint8_t flags; + uint8_t failure_fatal; Signature *sig_list; uint32_t sig_cnt; diff --git a/src/eidps.c b/src/eidps.c index 2b0a34a693..2fbea6c0e8 100644 --- a/src/eidps.c +++ b/src/eidps.c @@ -309,6 +309,8 @@ int main(int argc, char **argv) {"pfring-clusterid", required_argument, 0, 0}, {"unittest-filter", required_argument, 0, 'U'}, {"list-unittests", 0, &list_unittests, 1}, + {"init-errors-fatal", 0, 0, 0}, + {"fatal-unittests", 0, 0, 0}, {NULL, 0, NULL, 0} }; @@ -334,6 +336,12 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } } + else if(strcmp((long_opts[option_index]).name, "init-errors-fatal") == 0) { + if (ConfSet("engine.init_failure_fatal", "1", 0) != 1) { + fprintf(stderr, "ERROR: Failed to set engine init_failure_fatal.\n"); + exit(EXIT_FAILURE); + } + } else if(strcmp((long_opts[option_index]).name, "list-unittests") == 0) { #ifdef UNITTESTS /* Set mode to unit tests. */ @@ -341,6 +349,17 @@ int main(int argc, char **argv) #else fprintf(stderr, "ERROR: Unit tests not enabled. Make sure to pass --enable-unittests to configure when building.\n"); exit(EXIT_FAILURE); +#endif /* UNITTESTS */ + } + else if(strcmp((long_opts[option_index]).name, "fatal-unittests") == 0) { +#ifdef UNITTESTS + if (ConfSet("unittests.failure_fatal", "1", 0) != 1) { + fprintf(stderr, "ERROR: Failed to set unittests failure_fatal.\n"); + exit(EXIT_FAILURE); + } +#else + fprintf(stderr, "ERROR: Unit tests not enabled. Make sure to pass --enable-unittests to configure when building.\n"); + exit(EXIT_FAILURE); #endif /* UNITTESTS */ } break; diff --git a/src/util-unittest.c b/src/util-unittest.c index 1fb49d87e5..c4d073e460 100644 --- a/src/util-unittest.c +++ b/src/util-unittest.c @@ -9,6 +9,7 @@ #include "util-unittest.h" #include "util-debug.h" #include "util-time.h" +#include "conf.h" static pcre *parse_regex; static pcre_extra *parse_regex_study; @@ -157,6 +158,12 @@ uint32_t UtRunTests(char *regex_arg) { uint32_t good = 0, bad = 0, matchcnt = 0; int ret = 0, rcomp = 0; int ov[MAX_SUBSTRINGS]; + int failure_fatal; + + if (ConfGetBool("unittests.failure_fatal", &failure_fatal) != 1) { + SCLogDebug("ConfGetBool could not load the value."); + failure_fatal = 0; + } rcomp = UtRegex(regex_arg); @@ -175,6 +182,10 @@ uint32_t UtRunTests(char *regex_arg) { ret = ut->TestFn(); printf("%s\n", (ret == ut->evalue) ? "pass" : "FAILED"); if (ret != ut->evalue) { + if (failure_fatal == 1) { + fprintf(stderr, "ERROR: unittest failed.\n"); + exit(EXIT_FAILURE); + } bad++; } else { good++;