From: Jason Ish Date: Wed, 29 Nov 2023 18:57:23 +0000 (-0600) Subject: detect-parse: parse sid in pre-scan X-Git-Tag: suricata-8.0.0-beta1~1899 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71bbba9248e696f0fd2e912ad9631052b3788775;p=thirdparty%2Fsuricata.git detect-parse: parse sid in pre-scan 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. --- diff --git a/src/detect-parse.c b/src/detect-parse.c index 493bee10ea..45f188df11 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -900,10 +900,11 @@ static int SigParseOptions(DetectEngineCtx *de_ctx, Signature *s, char *optstr, } optname = optstr; - if (requires) { - if (strcmp(optname, "requires")) { - goto finish; - } + /* Check for options that are only to be processed during the + * first "requires" pass. */ + bool requires_only = strcmp(optname, "requires") == 0 || strcmp(optname, "sid") == 0; + if ((requires && !requires_only) || (!requires && requires_only)) { + goto finish; } /* Call option parsing */ @@ -2137,10 +2138,7 @@ static int SigValidate(DetectEngineCtx *de_ctx, Signature *s) AppLayerHtpNeedFileInspection(); } } - if (s->id == 0) { - SCLogError("Signature missing required value \"sid\"."); - SCReturnInt(0); - } + SCReturnInt(1); } @@ -2181,6 +2179,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);