Skip to content

Commit

Permalink
detect/bytejump: Improve end-of-buffer handling
Browse files Browse the repository at this point in the history
Issue: 4623

This commit addresses the issues reported in issue 4623 when the jump
value points at the last byte in the buffer.
  • Loading branch information
jlucovsky committed Oct 27, 2023
1 parent e644c2c commit 5699d58
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/detect-bytejump.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,19 @@ bool DetectBytejumpDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s,
/* Calculate the ptr value for the bytejump and length remaining in
* the packet from that point.
*/
ptr = payload;
len = payload_len;
ptr = payload + offset;
len = payload_len - offset;
if (flags & DETECT_BYTEJUMP_RELATIVE) {
ptr += det_ctx->buffer_offset;
len -= det_ctx->buffer_offset;

ptr += offset;
len -= offset;
SCLogDebug("[relative] after: ptr %p [len %d]", ptr, len);

/* No match if there is no relative base */
if (ptr == NULL || len <= 0) {
if (ptr == NULL || (nbytes && len <= 0)) {
SCReturnBool(false);
}
}
else {
ptr += offset;
len -= offset;
}

/* Verify the to-be-extracted data is within the packet */
if (ptr < payload || nbytes > len) {
Expand Down Expand Up @@ -243,7 +238,7 @@ bool DetectBytejumpDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s,
if (jumpptr < payload) {
jumpptr = payload;
SCLogDebug("jump location is before buffer start; resetting to buffer start");
} else if (jumpptr >= (payload + payload_len)) {
} else if (jumpptr > (payload + payload_len)) {
SCLogDebug("Jump location (%" PRIu64 ") is not within payload (%" PRIu32 ")",
payload_len + val, payload_len);
SCReturnBool(false);
Expand Down

0 comments on commit 5699d58

Please sign in to comment.