From: Victor Julien Date: Tue, 28 Jun 2022 13:29:11 +0000 (+0200) Subject: mime: add base64 related debug messages X-Git-Tag: suricata-5.0.10~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=63a319f9cbd653e59d4fe6afbb70c5f427755cdc;p=thirdparty%2Fsuricata.git mime: add base64 related debug messages (cherry picked from commit 5805ed47f51edbb2319f687cfa4fe503d6f0f0e3) --- diff --git a/src/util-decode-mime.c b/src/util-decode-mime.c index 49fa2149bb..66b22bb87c 100644 --- a/src/util-decode-mime.c +++ b/src/util-decode-mime.c @@ -1208,6 +1208,8 @@ static uint8_t ProcessBase64Remainder( uint32_t cnt = 0; uint8_t block[B64_BLOCK]; + SCLogDebug("len %u force %d", len, force); + /* should be impossible, but lets be defensive */ DEBUG_VALIDATE_BUG_ON(state->bvr_len > B64_BLOCK); if (state->bvr_len > B64_BLOCK) { @@ -1258,9 +1260,13 @@ static uint8_t ProcessBase64Remainder( uint32_t consumed_bytes = 0; uint32_t remdec = 0; const uint32_t avail_space = DATA_CHUNK_SIZE - state->data_chunk_len; + PrintChars(SC_LOG_DEBUG, "BASE64 INPUT (bvremain)", state->bvremain, state->bvr_len); Base64Ecode code = DecodeBase64(state->data_chunk + state->data_chunk_len, avail_space, state->bvremain, state->bvr_len, &consumed_bytes, &remdec, BASE64_MODE_RFC2045); + SCLogDebug("DecodeBase64 result %u", code); if (remdec > 0 && (code == BASE64_ECODE_OK || code == BASE64_ECODE_BUF)) { + PrintChars(SC_LOG_DEBUG, "BASE64 DECODED (bvremain)", + state->data_chunk + state->data_chunk_len, remdec); /* Track decoded length */ state->stack->top->data->decoded_body_len += remdec; @@ -1351,14 +1357,19 @@ static int ProcessBase64BodyLine(const uint8_t *buf, uint32_t len, while (remaining > 0 && remaining >= B64_BLOCK) { uint32_t consumed_bytes = 0; uint32_t avail_space = DATA_CHUNK_SIZE - state->data_chunk_len; + PrintChars(SC_LOG_DEBUG, "BASE64 INPUT (line)", buf + offset, remaining); Base64Ecode code = DecodeBase64(state->data_chunk + state->data_chunk_len, avail_space, buf + offset, remaining, &consumed_bytes, &numDecoded, BASE64_MODE_RFC2045); + SCLogDebug("DecodeBase64 result %u", code); DEBUG_VALIDATE_BUG_ON(consumed_bytes > remaining); if (consumed_bytes > remaining) return MIME_DEC_ERR_PARSE; uint32_t leftover_bytes = remaining - consumed_bytes; if (numDecoded > 0 && (code == BASE64_ECODE_OK || code == BASE64_ECODE_BUF)) { + PrintChars(SC_LOG_DEBUG, "BASE64 DECODED (line)", + state->data_chunk + state->data_chunk_len, numDecoded); + /* Track decoded length */ state->stack->top->data->decoded_body_len += numDecoded; /* Update length */