Skip to content

Commit

Permalink
detect-parse: parse sid in pre-scan
Browse files Browse the repository at this point in the history
During the pre-scan for "requires", also parse the SID if possible. If
the rule fails high level parsing (syntax), the SID will not be
parsed.

But every keyword other than "sid" and "requires" should expect to be
provided with a parsed sid.
  • Loading branch information
jasonish committed Nov 29, 2023
1 parent 96cbacb commit 8620b1b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/detect-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ static int SigParseOptions(DetectEngineCtx *de_ctx, Signature *s, char *optstr,
optname = optstr;

if (requires) {
if (strcmp(optname, "requires")) {
if (strcmp(optname, "requires") && strcmp(optname, "sid")) {
goto finish;
}
}
Expand Down Expand Up @@ -2139,10 +2139,7 @@ static int SigValidate(DetectEngineCtx *de_ctx, Signature *s)
AppLayerHtpNeedFileInspection();
}
}
if (s->id == 0) {
SCLogError("Signature missing required value \"sid\".");
SCReturnInt(0);
}

SCReturnInt(1);
}

Expand Down Expand Up @@ -2183,6 +2180,12 @@ static Signature *SigInitHelper(DetectEngineCtx *de_ctx, const char *sigstr,
goto error;
}

/* Check for a SID before continuuing. */
if (sig->id == 0) {
SCLogError("Signature missing required value \"sid\".");
goto error;
}

/* Now completely parse the rule. */
ret = SigParse(de_ctx, sig, sigstr, dir, &parser, false);
BUG_ON(ret == -4);
Expand Down

0 comments on commit 8620b1b

Please sign in to comment.