]> 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, 31 Jan 2022 07:54:42 +0000 (08:54 +0100)
instead of checking afterwards if value got smaller

rust/src/http2/parser.rs

index f228edfa5bdb60a33bd415afee75f1a76e1f1338..a99a5bda15ac9e79ddb1674a5603e7b087d59c78 100644 (file)
@@ -530,11 +530,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()) > u64::MAX - varval {
+        // this would overflow u64
         return Ok((i3, 0));
     }
+    varval += (finalv as u64) << (7 * varia.len());
     return Ok((i3, varval));
 }