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;
return !DetectLongContentTestCommon(sig, 1);
}
-#endif /* UNITTESTS */
+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;
+}
+#endif
/**
* \brief this function registers unit tests for DetectContent
UtRegisterTest("DetectLongContentTest1", DetectLongContentTest1);
UtRegisterTest("DetectLongContentTest2", DetectLongContentTest2);
UtRegisterTest("DetectLongContentTest3", DetectLongContentTest3);
+
+ UtRegisterTest("DetectBadBinContent", DetectBadBinContent);
#endif /* UNITTESTS */
}