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
(cherry picked from commit a3168fd)
  • Loading branch information
catenacyber authored and victorjulien committed Jun 30, 2023
1 parent 4432b47 commit 86ed6cd
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/util-decode-mime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2244,18 +2244,6 @@ static int ProcessMimeBody(const uint8_t *buf, uint32_t len,
int body_found = 0;
uint32_t tlen;

#ifdef HAVE_NSS
if (MimeDecGetConfig()->body_md5) {
if (state->body_begin == 1) {
if (state->md5_ctx == NULL) {
state->md5_ctx = HASH_Create(HASH_AlgMD5);
HASH_Begin(state->md5_ctx);
}
}
HASH_Update(state->md5_ctx, buf, len + state->current_line_delimiter_len);
}
#endif

/* 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 @@ -2385,6 +2373,21 @@ static int ProcessMimeEntity(const uint8_t *buf, uint32_t len,
MAX_LINE_LEN);
}

if ((state->state_flag != HEADER_READY && state->state_flag != HEADER_STARTED) ||
(state->stack->top->data->ctnt_flags & CTNT_IS_BODYPART)) {
#ifdef HAVE_NSS
if (MimeDecGetConfig()->body_md5) {
if (state->body_begin == 1) {
if (state->md5_ctx == NULL) {
state->md5_ctx = HASH_Create(HASH_AlgMD5);
HASH_Begin(state->md5_ctx);
}
}
HASH_Update(state->md5_ctx, buf, len + state->current_line_delimiter_len);
}
#endif
}

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

0 comments on commit 86ed6cd

Please sign in to comment.