]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
util/mime: adds safety check
authorPhilippe Antoine <pantoine@oisf.net>
Thu, 18 Apr 2024 11:36:34 +0000 (13:36 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 19 Apr 2024 18:51:25 +0000 (20:51 +0200)
Ticket: 6904

Even if there is no problem, just fortify the function,
so that it is future-proof if the caller does not do the check.

src/util-decode-mime.c

index 26da88363277ec62f56977eb22ed076870501167..533ae971d774e8f84221a03445f27348d4a55869 100644 (file)
@@ -617,6 +617,11 @@ static uint8_t *GetFullValue(const DataValue *dv, uint32_t *olen)
 
     /* First calculate total length */
     for (const DataValue *curr = dv; curr != NULL; curr = curr->next) {
+        if (unlikely(len > UINT32_MAX - curr->value_len)) {
+            // This should never happen as caller checks already against mdcfg->header_value_depth
+            DEBUG_VALIDATE_BUG_ON(1);
+            return NULL;
+        }
         len += curr->value_len;
     }
     /* Must have at least one character in the value */