Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonish committed Nov 23, 2023
1 parent 5fcb8e4 commit 782f1b2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 deletions.
32 changes: 19 additions & 13 deletions src/detect-engine-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ char *DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_f
* \param badsigs_tot Will store number of invalid signatures in the file
* \retval 0 on success, -1 on error
*/
static int DetectLoadSigFile(DetectEngineCtx *de_ctx, char *sig_file,
int *goodsigs, int *badsigs, int *skippedsigs)
static int DetectLoadSigFile(
DetectEngineCtx *de_ctx, char *sig_file, int *goodsigs, int *badsigs, int *skippedsigs)
{
Signature *sig = NULL;
int good = 0, bad = 0, skipped = 0;
Expand Down Expand Up @@ -196,10 +196,12 @@ static int DetectLoadSigFile(DetectEngineCtx *de_ctx, char *sig_file,
if (!de_ctx->sigerror_ok) {
bad++;
}
if (de_ctx->sigerror_requires) {
SCLogInfo("Skipping signature due to missing requirements: %s from file %s at line %"PRId32, line, sig_file, lineno - multiline);
skipped++;
}
if (de_ctx->sigerror_requires) {
SCLogInfo("Skipping signature due to missing requirements: %s from file %s at line "
"%" PRId32,
line, sig_file, lineno - multiline);
skipped++;
}
}
multiline = 0;
}
Expand All @@ -217,8 +219,8 @@ static int DetectLoadSigFile(DetectEngineCtx *de_ctx, char *sig_file,
* \param sig_file Filename (or pattern) holding signatures
* \retval -1 on error
*/
static int ProcessSigFiles(DetectEngineCtx *de_ctx, char *pattern,
SigFileLoaderStat *st, int *good_sigs, int *bad_sigs, int *skipped_sigs)
static int ProcessSigFiles(DetectEngineCtx *de_ctx, char *pattern, SigFileLoaderStat *st,
int *good_sigs, int *bad_sigs, int *skipped_sigs)
{
int r = 0;

Expand Down Expand Up @@ -264,7 +266,7 @@ static int ProcessSigFiles(DetectEngineCtx *de_ctx, char *pattern,

st->good_sigs_total += *good_sigs;
st->bad_sigs_total += *bad_sigs;
st->skipped_sigs_total += *skipped_sigs;
st->skipped_sigs_total += *skipped_sigs;

#ifdef HAVE_GLOB_H
}
Expand Down Expand Up @@ -315,7 +317,8 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exc
TAILQ_FOREACH(file, &rule_files->head, next) {
sfile = DetectLoadCompleteSigPath(de_ctx, file->val);
good_sigs = bad_sigs = skipped_sigs = 0;
ret = ProcessSigFiles(de_ctx, sfile, sig_stat, &good_sigs, &bad_sigs, &skipped_sigs);
ret = ProcessSigFiles(
de_ctx, sfile, sig_stat, &good_sigs, &bad_sigs, &skipped_sigs);
SCFree(sfile);

if (de_ctx->failure_fatal && ret != 0) {
Expand Down Expand Up @@ -360,13 +363,16 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, bool sig_file_exc
/* we report the total of files and rules successfully loaded and failed */
if (strlen(de_ctx->config_prefix) > 0)
SCLogInfo("tenant id %d: %" PRId32 " rule files processed. %" PRId32
" rules successfully loaded, %" PRId32 " rules failed, %" PRId32 " rules skipped",
" rules successfully loaded, %" PRId32 " rules failed, %" PRId32
" rules skipped",
de_ctx->tenant_id, sig_stat->total_files, sig_stat->good_sigs_total,
sig_stat->bad_sigs_total, sig_stat->skipped_sigs_total);
else
SCLogInfo("%" PRId32 " rule files processed. %" PRId32
" rules successfully loaded, %" PRId32 " rules failed, %" PRId32 " rules skipped",
sig_stat->total_files, sig_stat->good_sigs_total, sig_stat->bad_sigs_total, sig_stat->skipped_sigs_total);
" rules successfully loaded, %" PRId32 " rules failed, %" PRId32
" rules skipped",
sig_stat->total_files, sig_stat->good_sigs_total, sig_stat->bad_sigs_total,
sig_stat->skipped_sigs_total);
}

if ((sig_stat->bad_sigs_total || sig_stat->bad_files) && de_ctx->failure_fatal) {
Expand Down
12 changes: 5 additions & 7 deletions src/detect-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2149,18 +2149,16 @@ static Signature *SigInitHelper(DetectEngineCtx *de_ctx, const char *sigstr,

int ret = SigParse(de_ctx, sig, sigstr, dir, &parser);
if (ret == -4) {
/* Rule requirements not met. */
/* Rule requirements not met. */
de_ctx->sigerror_silent = true;
de_ctx->sigerror_ok = true;
de_ctx->sigerror_requires = true;
goto error;
}
else if (ret == -3) {
de_ctx->sigerror_requires = true;
goto error;
} else if (ret == -3) {
de_ctx->sigerror_silent = true;
de_ctx->sigerror_ok = true;
goto error;
}
else if (ret == -2) {
} else if (ret == -2) {
de_ctx->sigerror_silent = true;
goto error;
} else if (ret < 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/detect-requires.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ static int DetectRequiresSetup(DetectEngineCtx *de_ctx, Signature *s, const char
const char *errmsg = NULL;
int res = SCDetectCheckRequires(rawstr, PROG_VER, &errmsg);
if (res == -1) {
// The requires expression is bad, log an error.
SCLogError("%s: %s", errmsg, rawstr);
de_ctx->sigerror = errmsg;
// The requires expression is bad, log an error.
SCLogError("%s: %s", errmsg, rawstr);
de_ctx->sigerror = errmsg;
} else if (res == -4) {
// This Suricata instance didn't meet the requirements.
SCLogInfo("Suricata did not meet the rules requirements: %s: %s", errmsg, rawstr);
// This Suricata instance didn't meet the requirements.
SCLogInfo("Suricata did not meet the rules requirements: %s: %s", errmsg, rawstr);
}
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/detect.h
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ typedef struct DetectEngineCtx_ {
const char *sigerror;
bool sigerror_silent;
bool sigerror_ok;

/** The rule errored out due to missing requirements. */
bool sigerror_requires;

Expand Down

0 comments on commit 782f1b2

Please sign in to comment.