Skip to content

Commit

Permalink
detect/base64: minor cleanups
Browse files Browse the repository at this point in the history
1. decode_len can be u32 as it stores min of two u32s.
2. Add defensive check for payload_len calculation underflow.
  • Loading branch information
inashivb committed Sep 19, 2024
1 parent 33074b6 commit 3c73141
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/detect-base64-decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ int DetectBase64DecodeDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s
const SigMatchData *smd, const uint8_t *payload, uint32_t payload_len)
{
DetectBase64Decode *data = (DetectBase64Decode *)smd->ctx;
int decode_len;

#if 0
printf("Input data:\n");
Expand All @@ -76,6 +75,7 @@ int DetectBase64DecodeDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s

if (data->relative) {
payload += det_ctx->buffer_offset;
DEBUG_VALIDATE_BUG_ON(det_ctx->buffer_offset > payload_len);
payload_len -= det_ctx->buffer_offset;
}

Expand All @@ -87,9 +87,7 @@ int DetectBase64DecodeDoMatch(DetectEngineThreadCtx *det_ctx, const Signature *s
payload_len -= data->offset;
}

decode_len = MIN(payload_len, data->bytes);

DEBUG_VALIDATE_BUG_ON(decode_len < 0);
uint32_t decode_len = MIN(payload_len, data->bytes);
#if 0
printf("Decoding:\n");
PrintRawDataFp(stdout, payload, decode_len);
Expand Down

0 comments on commit 3c73141

Please # to comment.