]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http2: check overflow before it happens
authorPhilippe Antoine <contact@catenacyber.fr>
Sun, 23 Jan 2022 20:22:32 +0000 (21:22 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 5 Sep 2022 09:59:44 +0000 (11:59 +0200)
instead of checking afterwards if value got smaller

(cherry picked from commit b86beb9b68807e371f7af1ad6a1f789fdd5f7209)

Manually adapted to make it work with MSRV

rust/src/http2/parser.rs

index 87e988389570f0707715c45f0d00eebf5f0b632d..cc76f225c3a651bab3df7c979c00a6273a73a0eb 100644 (file)
@@ -528,11 +528,11 @@ fn http2_parse_var_uint(input: &[u8], value: u64, max: u64) -> IResult<&[u8], u6
     for i in 0..varia.len() {
         varval += ((varia[i] & 0x7F) as u64) << (7 * i);
     }
-    varval += (finalv as u64) << (7 * varia.len());
-    if varval < max {
-        // this has overflown u64
+    if (finalv as u64) << (7 * varia.len()) > std::u64::MAX - varval {
+        // this would overflow u64
         return Ok((i3, 0));
     }
+    varval += (finalv as u64) << (7 * varia.len());
     return Ok((i3, varval));
 }