]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/base64: check for dest buf size in last block
authorShivani Bhardwaj <shivani@oisf.net>
Thu, 30 Mar 2023 07:41:12 +0000 (13:11 +0530)
committerShivani Bhardwaj <shivanib134@gmail.com>
Tue, 25 Jul 2023 14:59:36 +0000 (20:29 +0530)
Just like the check for destination buffer size done previously for
complete data, it should also be done for the trailing data to avoid
goind out of bounds.

(cherry picked from commit 0e8b451699218b3f3430d7614f76cffed7ba991c)

src/util-base64.c

index 1c99dc636724cdd5ca93ef87328ce25a9b1aa87e..678bc14c66baba4f5f04ad93379c15bd4e0916c4 100644 (file)
@@ -158,7 +158,13 @@ Base64Ecode DecodeBase64(uint8_t *dest, uint32_t dest_size, const uint8_t *src,
     if (bbidx > 0 && bbidx < 4 && ((!valid && mode == BASE64_MODE_RFC4648))) {
         /* Decoded bytes for 1 or 2 base64 encoded bytes is 1 */
         padding = bbidx > 1 ? B64_BLOCK - bbidx : 2;
-        *decoded_bytes += ASCII_BLOCK - padding;
+        uint32_t numDecoded_blk = ASCII_BLOCK - (padding < B64_BLOCK ? padding : ASCII_BLOCK);
+        if (dest_size < *decoded_bytes + numDecoded_blk) {
+            SCLogDebug("Destination buffer full");
+            ecode = BASE64_ECODE_BUF;
+            return ecode;
+        }
+        *decoded_bytes += numDecoded_blk;
         DecodeBase64Block(dptr, b64);
         *consumed_bytes += bbidx;
     }