Skip to content

Commit e1cc9c0

Browse files
committed
Disconnect on handling frames from unknown streams
Signed-off-by: Eloi DEMOLIS <[email protected]>
1 parent d0a21ba commit e1cc9c0

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

lib/src/protocol/mux/converter.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::str::from_utf8_unchecked;
2-
31
use kawa::{
42
AsBuffer, Block, BlockConverter, Chunk, Flags, Kawa, Pair, ParsingErrorKind, ParsingPhase,
53
StatusLine, Store,
@@ -107,7 +105,6 @@ impl<'a, T: AsBuffer> BlockConverter<T> for H2BlockConverter<'a> {
107105
|| compare_no_case(key, b"transfer-encoding")
108106
|| compare_no_case(key, b"upgrade")
109107
{
110-
println!("Elided H2 header: {}", unsafe { from_utf8_unchecked(key) });
111108
return true;
112109
}
113110
}

lib/src/protocol/mux/h2.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,12 @@ impl<Front: SocketHandler> ConnectionH2<Front> {
739739
match frame {
740740
Frame::Data(data) => {
741741
let mut slice = data.payload;
742-
// can this fail?
743-
let global_stream_id = *self.streams.get(&data.stream_id).unwrap();
742+
// can this fail? yes
743+
let Some(global_stream_id) = self.streams.get(&data.stream_id).copied() else {
744+
error!("Handling Data frame with no attached stream {:#?}", self);
745+
incr!("h2.data_no_stream.error");
746+
return self.force_disconnect();
747+
};
744748
let stream = &mut context.streams[global_stream_id];
745749
let parts = stream.split(&self.position);
746750
let kawa = parts.rbuffer;
@@ -778,7 +782,11 @@ impl<Front: SocketHandler> ConnectionH2<Front> {
778782
}
779783
// can this fail?
780784
let stream_id = headers.stream_id;
781-
let global_stream_id = *self.streams.get(&stream_id).unwrap();
785+
let Some(global_stream_id) = self.streams.get(&stream_id).copied() else {
786+
error!("Handling Headers frame with no attached stream {:#?}", self);
787+
incr!("h2.headers_no_stream.error");
788+
return self.force_disconnect();
789+
};
782790

783791
if let Some(priority) = &headers.priority {
784792
if self.prioriser.push_priority(stream_id, priority.clone()) {

lib/src/protocol/mux/pkawa.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ where
103103
}
104104
} else if compare_no_case(&k, b"priority") {
105105
// todo!("decode priority");
106-
warn!("DECODE PRIORITY: {}", unsafe {
107-
std::str::from_utf8_unchecked(v.as_ref())
108-
});
109106
prioriser.push_priority(
110107
stream_id,
111108
PriorityPart::Rfc9218 {

0 commit comments

Comments
 (0)