]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mime: replace small memcpy with loop
authorVictor Julien <vjulien@oisf.net>
Fri, 21 Jul 2023 08:05:41 +0000 (10:05 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 25 Jul 2023 13:09:33 +0000 (15:09 +0200)
To address:

      In file included from /usr/include/string.h:535,
                 from suricata-common.h:108,
                 from util-decode-mime.c:26:
In function ‘memcpy’,
    inlined from ‘ProcessBase64Remainder’ at util-decode-mime.c:1201:13:
/usr/include/mipsel-linux-gnu/bits/string_fortified.h:29:10: warning: ‘__builtin_memcpy’ forming offset 4 is out of the bounds [0, 4] of object ‘block’ with type ‘uint8_t[4]’ {aka ‘unsigned char[4]’} [-Warray-bounds=]
   29 |   return __builtin___memcpy_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   30 |                                  __glibc_objsize0 (__dest));
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~
util-decode-mime.c: In function ‘ProcessBase64Remainder’:
util-decode-mime.c:1174:13: note: ‘block’ declared here
 1174 |     uint8_t block[B64_BLOCK];
      |             ^~~~~

Copy data should be <= 4 bytes.

src/util-decode-mime.c

index e13216118a0b4ca46716cfcbbc9ac74b197e98db..7ee5263b769c63932291098823663c6fd8ac487a 100644 (file)
@@ -1197,8 +1197,9 @@ static uint32_t ProcessBase64Remainder(
             }
             buf_consumed++;
         }
-        if (cnt != 0) {
-            memcpy(state->bvremain, block, cnt);
+        DEBUG_VALIDATE_BUG_ON(cnt > B64_BLOCK);
+        for (uint32_t i = 0; i < cnt; i++) {
+            state->bvremain[i] = block[i];
         }
         state->bvr_len = cnt;
     } else if (!force && cnt != B64_BLOCK) {