detect/content-inspect: flatten branches

Flatten else branches after terminating ifs.
pull/9999/head
Victor Julien 3 years ago committed by Victor Julien
parent 4cce7ba48b
commit c19d11ff0d

@ -307,7 +307,8 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx,
} else { } else {
goto match; goto match;
} }
} else { }
uint32_t match_offset = (uint32_t)((found - buffer) + cd->content_len); uint32_t match_offset = (uint32_t)((found - buffer) + cd->content_len);
if (cd->flags & DETECT_CONTENT_NEGATED) { if (cd->flags & DETECT_CONTENT_NEGATED) {
SCLogDebug("content %" PRIu32 " matched at offset %" PRIu32 SCLogDebug("content %" PRIu32 " matched at offset %" PRIu32
@ -329,9 +330,9 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx,
goto no_match_discontinue; goto no_match_discontinue;
} }
goto no_match; goto no_match;
} else { }
SCLogDebug("content %" PRIu32 " matched at offset %" PRIu32 "", cd->id,
match_offset); SCLogDebug("content %" PRIu32 " matched at offset %" PRIu32 "", cd->id, match_offset);
det_ctx->buffer_offset = match_offset; det_ctx->buffer_offset = match_offset;
if ((cd->flags & DETECT_CONTENT_ENDS_WITH) == 0 || match_offset == buffer_len) { if ((cd->flags & DETECT_CONTENT_ENDS_WITH) == 0 || match_offset == buffer_len) {
@ -340,8 +341,8 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx,
if (inspection_mode == DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD) { if (inspection_mode == DETECT_ENGINE_CONTENT_INSPECTION_MODE_PAYLOAD) {
/* we will need to replace content if match is confirmed /* we will need to replace content if match is confirmed
* cast to non-const as replace writes to it. */ * cast to non-const as replace writes to it. */
det_ctx->replist = DetectReplaceAddToList( det_ctx->replist =
det_ctx->replist, (uint8_t *)found, cd); DetectReplaceAddToList(det_ctx->replist, (uint8_t *)found, cd);
} else { } else {
SCLogWarning("Can't modify payload without packet"); SCLogWarning("Can't modify payload without packet");
} }
@ -358,8 +359,8 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx,
/* see if the next buffer keywords match. If not, we will /* see if the next buffer keywords match. If not, we will
* search for another occurrence of this content and see * search for another occurrence of this content and see
* if the others match then until we run out of matches */ * if the others match then until we run out of matches */
int r = DetectEngineContentInspectionInternal(det_ctx, ctx, s, smd + 1, p, int r = DetectEngineContentInspectionInternal(det_ctx, ctx, s, smd + 1, p, f,
f, buffer, buffer_len, stream_start_offset, flags, inspection_mode); buffer, buffer_len, stream_start_offset, flags, inspection_mode);
if (r == 1) { if (r == 1) {
SCReturnInt(1); SCReturnInt(1);
} else if (r == -1) { } else if (r == -1) {
@ -374,16 +375,13 @@ static int DetectEngineContentInspectionInternal(DetectEngineThreadCtx *det_ctx,
SCReturnInt(-1); SCReturnInt(-1);
} }
SCLogDebug("'next sm' depends on me %p, lets see what we can do (flags %u)", SCLogDebug("'next sm' depends on me %p, lets see what we can do (flags %u)", cd,
cd, cd->flags); cd->flags);
} }
/* set the previous match offset to the start of this match + 1 */ /* set the previous match offset to the start of this match + 1 */
prev_offset = (match_offset - (cd->content_len - 1)); prev_offset = (match_offset - (cd->content_len - 1));
SCLogDebug("trying to see if there is another match after prev_offset %" PRIu32, SCLogDebug("trying to see if there is another match after prev_offset %" PRIu32,
prev_offset); prev_offset);
}
}
} while(1); } while(1);
} else if (smd->type == DETECT_ISDATAAT) { } else if (smd->type == DETECT_ISDATAAT) {

Loading…
Cancel
Save