]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mime: add base64 related debug messages
authorVictor Julien <vjulien@oisf.net>
Tue, 28 Jun 2022 13:29:11 +0000 (15:29 +0200)
committerVictor Julien <vjulien@oisf.net>
Wed, 29 Jun 2022 18:00:46 +0000 (20:00 +0200)
(cherry picked from commit 5805ed47f51edbb2319f687cfa4fe503d6f0f0e3)

src/util-decode-mime.c

index edb4e317afae2be035b9a93ee0c2468e4277e72b..0e04ad8f13a756f113ff5c592e7b97093884b7e0 100644 (file)
@@ -1207,6 +1207,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) {
@@ -1257,9 +1259,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;
@@ -1350,14 +1356,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 */