-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Warnint 64to32 6186 v23 #12843
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
Warnint 64to32 6186 v23 #12843
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,7 +156,10 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx, | |
| int distance = cd->distance; | ||
| if (cd->flags & DETECT_CONTENT_DISTANCE) { | ||
| if (cd->flags & DETECT_CONTENT_DISTANCE_VAR) { | ||
| distance = det_ctx->byte_values[cd->distance]; | ||
| if (det_ctx->byte_values[cd->distance] > UINT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| distance = (uint32_t)det_ctx->byte_values[cd->distance]; | ||
| } | ||
| if (distance < 0 && (uint32_t)(abs(distance)) > offset) | ||
| offset = 0; | ||
|
|
@@ -170,7 +173,12 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx, | |
| if (cd->flags & DETECT_CONTENT_WITHIN) { | ||
| if (cd->flags & DETECT_CONTENT_WITHIN_VAR) { | ||
| if ((int32_t)depth > (int32_t)(prev_buffer_offset + det_ctx->byte_values[cd->within] + distance)) { | ||
| depth = prev_buffer_offset + det_ctx->byte_values[cd->within] + distance; | ||
| if (prev_buffer_offset + det_ctx->byte_values[cd->within] + distance > | ||
| UINT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| depth = (uint32_t)(prev_buffer_offset + | ||
| det_ctx->byte_values[cd->within] + distance); | ||
| } | ||
| } else { | ||
| if ((int32_t)depth > (int32_t)(prev_buffer_offset + cd->within + distance)) { | ||
|
|
@@ -194,7 +202,10 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx, | |
|
|
||
| if (cd->flags & DETECT_CONTENT_DEPTH_VAR) { | ||
| if ((det_ctx->byte_values[cd->depth] + prev_buffer_offset) < depth) { | ||
| depth = prev_buffer_offset + det_ctx->byte_values[cd->depth]; | ||
| if (prev_buffer_offset + det_ctx->byte_values[cd->depth] > UINT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| depth = (uint32_t)(prev_buffer_offset + det_ctx->byte_values[cd->depth]); | ||
| } | ||
| } else { | ||
| if (cd->depth != 0) { | ||
|
|
@@ -207,8 +218,12 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx, | |
| } | ||
|
|
||
| if (cd->flags & DETECT_CONTENT_OFFSET_VAR) { | ||
| if (det_ctx->byte_values[cd->offset] > offset) | ||
| offset = det_ctx->byte_values[cd->offset]; | ||
| if (det_ctx->byte_values[cd->offset] > offset) { | ||
| if (det_ctx->byte_values[cd->offset] > UINT32_MAX) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how would this happen? Can we avoid it from getting set? It seems painful to put all these checks here if we can avoid it
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think with a rule using |
||
| goto no_match; | ||
| } | ||
| offset = (uint32_t)det_ctx->byte_values[cd->offset]; | ||
| } | ||
| } else { | ||
| if (cd->offset > offset) { | ||
| offset = cd->offset; | ||
|
|
@@ -218,7 +233,10 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx, | |
| } else { /* implied no relative matches */ | ||
| /* set depth */ | ||
| if (cd->flags & DETECT_CONTENT_DEPTH_VAR) { | ||
| depth = det_ctx->byte_values[cd->depth]; | ||
| if (det_ctx->byte_values[cd->depth] > UINT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| depth = (uint32_t)det_ctx->byte_values[cd->depth]; | ||
| } else { | ||
| if (cd->depth != 0) { | ||
| depth = cd->depth; | ||
|
|
@@ -236,9 +254,12 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx, | |
| } | ||
|
|
||
| /* set offset */ | ||
| if (cd->flags & DETECT_CONTENT_OFFSET_VAR) | ||
| offset = det_ctx->byte_values[cd->offset]; | ||
| else | ||
| if (cd->flags & DETECT_CONTENT_OFFSET_VAR) { | ||
| if (det_ctx->byte_values[cd->offset] > UINT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| offset = (uint32_t)det_ctx->byte_values[cd->offset]; | ||
| } else | ||
| offset = cd->offset; | ||
| prev_buffer_offset = 0; | ||
| } | ||
|
|
@@ -493,13 +514,19 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx, | |
| uint64_t value = btd->value; | ||
| int32_t nbytes = btd->nbytes; | ||
| if (btflags & DETECT_BYTETEST_OFFSET_VAR) { | ||
| offset = det_ctx->byte_values[offset]; | ||
| if (det_ctx->byte_values[offset] > UINT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| offset = (uint32_t)det_ctx->byte_values[offset]; | ||
| } | ||
| if (btflags & DETECT_BYTETEST_VALUE_VAR) { | ||
| value = det_ctx->byte_values[value]; | ||
| } | ||
| if (btflags & DETECT_BYTETEST_NBYTES_VAR) { | ||
| nbytes = det_ctx->byte_values[nbytes]; | ||
| if (det_ctx->byte_values[nbytes] > INT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| nbytes = (int32_t)det_ctx->byte_values[nbytes]; | ||
| } | ||
|
|
||
| /* if we have dce enabled we will have to use the endianness | ||
|
|
@@ -525,11 +552,17 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx, | |
| int32_t nbytes; | ||
|
|
||
| if (bjflags & DETECT_BYTEJUMP_OFFSET_VAR) { | ||
| offset = det_ctx->byte_values[offset]; | ||
| if (det_ctx->byte_values[offset] > UINT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| offset = (uint32_t)det_ctx->byte_values[offset]; | ||
| } | ||
|
|
||
| if (bjflags & DETECT_BYTEJUMP_NBYTES_VAR) { | ||
| nbytes = det_ctx->byte_values[bjd->nbytes]; | ||
| if (det_ctx->byte_values[bjd->nbytes] > INT32_MAX) { | ||
| goto no_match; | ||
| } | ||
| nbytes = (int32_t)det_ctx->byte_values[bjd->nbytes]; | ||
| } else { | ||
| nbytes = bjd->nbytes; | ||
| } | ||
|
|
@@ -757,8 +790,11 @@ bool DetectEngineContentInspectionBuffer(DetectEngineCtx *de_ctx, DetectEngineTh | |
|
|
||
| det_ctx->buffer_offset = 0; | ||
|
|
||
| if (b->inspect_offset > UINT32_MAX) { | ||
| return false; | ||
| } | ||
| int r = DetectEngineContentInspectionInternal(det_ctx, &ctx, s, smd, p, f, b->inspect, | ||
| b->inspect_len, b->inspect_offset, b->flags, inspection_mode); | ||
| b->inspect_len, (uint32_t)b->inspect_offset, b->flags, inspection_mode); | ||
| #ifdef UNITTESTS | ||
| ut_inspection_recursion_counter = ctx.recursion.count; | ||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comes from unix socket
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we impose some limit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding one as there is also the stack allocation below