Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect-content: error on single char hex pairs - v3 #7168

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/detect-content.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ int DetectContentDataParse(const char *keyword, const char *contentstr,
if (str[i] == '|') {
bin_count++;
if (bin) {
if (binpos > 0) {
SCLogError(SC_ERR_INVALID_SIGNATURE,
"Incomplete hex code in content - %s. Invalidating signature.",
contentstr);
goto error;
}
bin = 0;
} else {
bin = 1;
Expand Down Expand Up @@ -3050,6 +3056,25 @@ static int DetectLongContentTest3(void)
return !DetectLongContentTestCommon(sig, 1);
}

static int DetectBadBinContent(void)
{
DetectEngineCtx *de_ctx = NULL;
de_ctx = DetectEngineCtxInit();
FAIL_IF_NULL(de_ctx);
de_ctx->flags |= DE_QUIET;
FAIL_IF_NOT_NULL(DetectEngineAppendSig(
de_ctx, "alert tcp any any -> any any (msg:\"test\"; content:\"|a|\"; sid:1;)"));
FAIL_IF_NOT_NULL(DetectEngineAppendSig(
de_ctx, "alert tcp any any -> any any (msg:\"test\"; content:\"|aa b|\"; sid:1;)"));
FAIL_IF_NOT_NULL(DetectEngineAppendSig(
de_ctx, "alert tcp any any -> any any (msg:\"test\"; content:\"|aa bz|\"; sid:1;)"));
/* https://redmine.openinfosecfoundation.org/issues/5201 */
FAIL_IF_NOT_NULL(DetectEngineAppendSig(
de_ctx, "alert tcp any any -> any any (msg:\"test\"; content:\"|22 2 22|\"; sid:1;)"));
DetectEngineCtxFree(de_ctx);
PASS;
}

/**
* \brief this function registers unit tests for DetectContent
*/
Expand Down Expand Up @@ -3168,5 +3193,7 @@ static void DetectContentRegisterTests(void)
UtRegisterTest("DetectLongContentTest1", DetectLongContentTest1);
UtRegisterTest("DetectLongContentTest2", DetectLongContentTest2);
UtRegisterTest("DetectLongContentTest3", DetectLongContentTest3);

UtRegisterTest("DetectBadBinContent", DetectBadBinContent);
}
#endif /* UNITTESTS */