]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http2: returns error in case of index 0
authorPhilippe Antoine <contact@catenacyber.fr>
Tue, 8 Sep 2020 14:23:29 +0000 (16:23 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 8 Sep 2020 15:40:48 +0000 (17:40 +0200)
As is documented in RFC 7541, section 6.1
The index value of 0 is not used.  It MUST be treated as a decoding
error if found in an indexed header field representation.

rust/src/http2/parser.rs

index d357e273c301ccba8936b8fc5d248a3d9c778a29..64ea876c96806084c02b2781b510233bbf884298 100644 (file)
@@ -285,7 +285,14 @@ fn http2_frame_header_static(
         });
     } else {
         //use dynamic table
-        if dyn_headers.len() + HTTP2_STATIC_HEADERS_NUMBER < n as usize {
+        if n == 0 {
+            return Some(HTTP2FrameHeaderBlock {
+                name: Vec::new(),
+                value: Vec::new(),
+                error: HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeIndex0,
+                sizeupdate: 0,
+            });
+        } else if dyn_headers.len() + HTTP2_STATIC_HEADERS_NUMBER < n as usize {
             return Some(HTTP2FrameHeaderBlock {
                 name: Vec::new(),
                 value: Vec::new(),
@@ -313,6 +320,7 @@ pub enum HTTP2HeaderDecodeStatus {
     HTTP2HeaderDecodeError = 0x80,
     HTTP2HeaderDecodeNotIndexed = 0x81,
     HTTP2HeaderDecodeIntegerOverflow = 0x82,
+    HTTP2HeaderDecodeIndex0 = 0x83,
 }
 
 impl fmt::Display for HTTP2HeaderDecodeStatus {
@@ -949,6 +957,21 @@ mod tests {
                 panic!("Result should not be an error: {:?}.", err);
             }
         }
+        let buf4: &[u8] = &[0x80];
+        let r4 = http2_parse_headers_block(buf4, &mut dynh);
+        match r4 {
+            Ok((remainder, hd)) => {
+                assert_eq!(hd.error, HTTP2HeaderDecodeStatus::HTTP2HeaderDecodeIndex0);
+                assert_eq!(remainder.len(), 0);
+                assert_eq!(dynh.len(), 2);
+            }
+            Err(Err::Incomplete(_)) => {
+                panic!("Result should not have been incomplete.");
+            }
+            Err(Err::Error(err)) | Err(Err::Failure(err)) => {
+                panic!("Result should not be an error: {:?}.", err);
+            }
+        }
         let buf2: &[u8] = &[
             0x04, 0x94, 0x62, 0x43, 0x91, 0x8a, 0x47, 0x55, 0xa3, 0xa1, 0x89, 0xd3, 0x4d, 0x0c,
             0x1a, 0xa9, 0x0b, 0xe5, 0x79, 0xd3, 0x4d, 0x1f,