Skip to content

Commit

Permalink
detect/icmp: reject invalid rules for icode/itype
Browse files Browse the repository at this point in the history
  • Loading branch information
victorjulien committed Mar 3, 2021
1 parent 7d68359 commit 68f8b2f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
23 changes: 20 additions & 3 deletions src/detect-icode.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,25 @@ static DetectICodeData *DetectICodeParse(DetectEngineCtx *de_ctx, const char *ic
"valid", args[1]);
goto error;
}
if ((strcmp(args[0], ">")) == 0) icd->mode = DETECT_ICODE_GT;
else icd->mode = DETECT_ICODE_LT;
if ((strcmp(args[0], ">")) == 0) {
if (icd->code1 == 255) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"specified icmp code >%s is not "
"valid",
args[1]);
goto error;
}
icd->mode = DETECT_ICODE_GT;
} else {
if (icd->code1 == 0) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"specified icmp code <%s is not "
"valid",
args[1]);
goto error;
}
icd->mode = DETECT_ICODE_LT;
}
} else { /* no "<", ">" */
/* we have a range ("<>") */
if (args[2] != NULL) {
Expand Down Expand Up @@ -590,4 +607,4 @@ void DetectICodeRegisterTests(void)
UtRegisterTest("DetectICodeParseTest08", DetectICodeParseTest08);
UtRegisterTest("DetectICodeMatchTest01", DetectICodeMatchTest01);
}
#endif /* UNITTESTS */
#endif /* UNITTESTS */
23 changes: 20 additions & 3 deletions src/detect-itype.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,25 @@ static DetectITypeData *DetectITypeParse(DetectEngineCtx *de_ctx, const char *it
"valid", args[1]);
goto error;
}
if ((strcmp(args[0], ">")) == 0) itd->mode = DETECT_ITYPE_GT;
else itd->mode = DETECT_ITYPE_LT;
if ((strcmp(args[0], ">")) == 0) {
if (itd->type1 == 255) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"specified icmp type >%s is not "
"valid",
args[1]);
goto error;
}
itd->mode = DETECT_ITYPE_GT;
} else {
if (itd->type1 == 0) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"specified icmp type <%s is not "
"valid",
args[1]);
goto error;
}
itd->mode = DETECT_ITYPE_LT;
}
} else { /* no "<", ">" */
/* we have a range ("<>") */
if (args[2] != NULL) {
Expand Down Expand Up @@ -595,4 +612,4 @@ void DetectITypeRegisterTests(void)
UtRegisterTest("DetectITypeParseTest08", DetectITypeParseTest08);
UtRegisterTest("DetectITypeMatchTest01", DetectITypeMatchTest01);
}
#endif /* UNITTESTS */
#endif /* UNITTESTS */

0 comments on commit 68f8b2f

Please sign in to comment.