Skip to content

Commit

Permalink
mime: compute full body md5
Browse files Browse the repository at this point in the history
Previously, the problem was that nested headers/boundaries were not
used to compute the hash

Solution is to move up the call to the hash computation from
ProcessMimeBody to its caller ProcessMimeEntity, and add a set of
conditions to ensure that we are not in the principal headers.

Ticket: OISF#6185
  • Loading branch information
catenacyber authored and victorjulien committed Jun 29, 2023
1 parent 9ed571e commit 42a9377
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/util-decode-mime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2214,17 +2214,6 @@ static int ProcessMimeBody(const uint8_t *buf, uint32_t len,
int body_found = 0;
uint16_t tlen;

if (!g_disable_hashing) {
if (MimeDecGetConfig()->body_md5) {
if (state->body_begin == 1) {
if (state->md5_ctx == NULL) {
state->md5_ctx = SCMd5New();
}
}
SCMd5Update(state->md5_ctx, buf, len + state->current_line_delimiter_len);
}
}

/* pass empty lines on if we're parsing the body, otherwise we have no use
* for them, and in fact they would disrupt the state tracking */
if (len == 0) {
Expand Down Expand Up @@ -2354,6 +2343,18 @@ static int ProcessMimeEntity(const uint8_t *buf, uint32_t len,
MAX_LINE_LEN);
}

if (!g_disable_hashing) {
if ((state->state_flag != HEADER_READY && state->state_flag != HEADER_STARTED) ||
(state->stack->top->data->ctnt_flags & CTNT_IS_BODYPART)) {
if (MimeDecGetConfig()->body_md5) {
if (state->body_begin == 1 && state->md5_ctx == NULL) {
state->md5_ctx = SCMd5New();
}
SCMd5Update(state->md5_ctx, buf, len + state->current_line_delimiter_len);
}
}
}

/* Looking for headers */
if (state->state_flag == HEADER_READY ||
state->state_flag == HEADER_STARTED) {
Expand Down

0 comments on commit 42a9377

Please sign in to comment.