mime: properly pass full lines to non-decoded body

Use actual delim count and make sure we also pass on empty lines
(so delim(s) only).
pull/7586/head
Victor Julien 4 years ago
parent 0d6ab727c5
commit b82b8825e7

@ -1566,7 +1566,7 @@ static int ProcessBodyLine(const uint8_t *buf, uint32_t len,
SCLogDebug("Processing body line"); SCLogDebug("Processing body line");
/* Track length */ /* Track length */
entity->body_len += len + 2; /* With CRLF */ entity->body_len += (len + state->current_line_delimiter_len);
/* Process base-64 content if enabled */ /* Process base-64 content if enabled */
MimeDecConfig *mdcfg = MimeDecGetConfig(); MimeDecConfig *mdcfg = MimeDecGetConfig();
@ -1587,24 +1587,17 @@ static int ProcessBodyLine(const uint8_t *buf, uint32_t len,
} }
} else { } else {
/* Process non-decoded content */ /* Process non-decoded content */
remaining = len; remaining = len + state->current_line_delimiter_len;
offset = 0; offset = 0;
while (remaining > 0) { while (remaining > 0) {
/* Plan to add CRLF to the end of each line */ /* Plan to add CRLF to the end of each line */
avail = DATA_CHUNK_SIZE - state->data_chunk_len; avail = DATA_CHUNK_SIZE - state->data_chunk_len;
tobuf = avail > remaining + EOL_LEN ? remaining : avail - EOL_LEN; tobuf = avail > remaining ? remaining : avail;
/* Copy over to buffer */ /* Copy over to buffer */
memcpy(state->data_chunk + state->data_chunk_len, buf + offset, tobuf); memcpy(state->data_chunk + state->data_chunk_len, buf + offset, tobuf);
state->data_chunk_len += tobuf; state->data_chunk_len += tobuf;
/* Now always add a CRLF to the end, unless its a partial line */
if (tobuf == remaining && state->current_line_delimiter_len > 0) {
memcpy(state->data_chunk + state->data_chunk_len, CRLF, EOL_LEN);
state->data_chunk_len += EOL_LEN;
}
if ((int) (DATA_CHUNK_SIZE - state->data_chunk_len) < 0) { if ((int) (DATA_CHUNK_SIZE - state->data_chunk_len) < 0) {
SCLogDebug("Error: Invalid Chunk length: %u", SCLogDebug("Error: Invalid Chunk length: %u",
state->data_chunk_len); state->data_chunk_len);
@ -1613,8 +1606,7 @@ static int ProcessBodyLine(const uint8_t *buf, uint32_t len,
} }
/* If buffer full, then invoke callback */ /* If buffer full, then invoke callback */
if (DATA_CHUNK_SIZE - state->data_chunk_len < EOL_LEN + 1) { if (DATA_CHUNK_SIZE - state->data_chunk_len == 0) {
/* Invoke pre-processor and callback */ /* Invoke pre-processor and callback */
ret = ProcessDecodedDataChunk(state->data_chunk, ret = ProcessDecodedDataChunk(state->data_chunk,
state->data_chunk_len, state); state->data_chunk_len, state);
@ -2246,11 +2238,6 @@ static int ProcessMimeBody(const uint8_t *buf, uint32_t len,
} }
} }
/* Ignore empty lines */
if (len == 0) {
return ret;
}
/* First look for boundary */ /* First look for boundary */
MimeDecStackNode *node = state->stack->top; MimeDecStackNode *node = state->stack->top;
if (node == NULL) { if (node == NULL) {

Loading…
Cancel
Save