Skip to content

Commit

Permalink
detect/pkt_data: error on unconsumed transforms
Browse files Browse the repository at this point in the history
If a rule has transforms w/o consuming them (e.g. a content keyword),
don't consider 'pkt_data' valid.
  • Loading branch information
victorjulien committed Mar 31, 2020
1 parent e1c474a commit 13c9d0c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/detect-pkt-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ void DetectPktDataRegister(void)
static int DetectPktDataSetup (DetectEngineCtx *de_ctx, Signature *s, const char *unused)
{
SCEnter();
if (s->init_data->transform_cnt) {
SCLogError(SC_ERR_INVALID_SIGNATURE,
"previous transforms not consumed before 'pkt_data'");
SCReturnInt(-1);
}
s->init_data->list = DETECT_SM_LIST_NOTSET;
SCReturnInt(0);
}
Expand Down Expand Up @@ -105,6 +110,19 @@ static int DetectPktDataTest01(void)
PASS;
}

static int DetectPktDataTest02(void)
{
DetectEngineCtx *de_ctx = DetectEngineCtxInit();
FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;

Signature *sig = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
"(file_data; compress_whitespace; "
" pkt_data; content:\"in pkt data\"; sid:1;)");
FAIL_IF_NOT_NULL(sig);
DetectEngineCtxFree(de_ctx);
PASS;
}
#endif

static void DetectPktDataTestRegister(void)
Expand All @@ -113,6 +131,7 @@ static void DetectPktDataTestRegister(void)
g_file_data_buffer_id = DetectBufferTypeGetByName("file_data");

UtRegisterTest("DetectPktDataTest01", DetectPktDataTest01);
UtRegisterTest("DetectPktDataTest02", DetectPktDataTest02);
#endif
}

0 comments on commit 13c9d0c

Please sign in to comment.