Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some missing bounds checks. #260

Merged
merged 2 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/frame/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ impl Headers {

// Read the padding length
if flags.is_padded() {
if src.len() < 1 {
return Err(Error::MalformedMessage);
}
// TODO: Ensure payload is sized correctly
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there's more involved, but wanted to check: does this addition essentially complete this TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it; I removed the comment.

pad = src[0] as usize;

Expand All @@ -162,6 +165,9 @@ impl Headers {

// Read the stream dependency
let stream_dep = if flags.is_priority() {
if src.len() < 5 {
return Err(Error::MalformedMessage);
}
let stream_dep = StreamDependency::load(&src[..5])?;

if stream_dep.dependency_id() == head.stream_id() {
Expand Down Expand Up @@ -290,13 +296,21 @@ impl PushPromise {

// Read the padding length
if flags.is_padded() {
if src.len() < 1 {
return Err(Error::MalformedMessage);
}

// TODO: Ensure payload is sized correctly
pad = src[0] as usize;

// Drop the padding
let _ = src.split_to(1);
}

if src.len() < 5 {
return Err(Error::MalformedMessage);
}

let (promised_id, _) = StreamId::parse(&src[..4]);
// Drop promised_id bytes
let _ = src.split_to(5);
Expand Down
5 changes: 4 additions & 1 deletion src/hpack/header.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::DecoderError;
use super::{DecoderError, NeedMore};

use bytes::Bytes;
use http::{Method, StatusCode};
Expand Down Expand Up @@ -60,6 +60,9 @@ impl Header<Option<HeaderName>> {

impl Header {
pub fn new(name: Bytes, value: Bytes) -> Result<Header, DecoderError> {
if name.len() == 0 {
return Err(DecoderError::NeedMore(NeedMore::UnexpectedEndOfStream));
}
if name[0] == b':' {
match &name[1..] {
b"authority" => {
Expand Down
2 changes: 1 addition & 1 deletion src/proto/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ where
// but should allow continuing to process current streams
// until they are all EOS. Once they are, State should
// transition to GoAway.
self.streams.recv_go_away(&frame);
self.streams.recv_go_away(&frame)?;
self.error = Some(frame.reason());
},
Some(Ping(frame)) => {
Expand Down
8 changes: 7 additions & 1 deletion src/proto/streams/streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ where
last_processed_id
}

pub fn recv_go_away(&mut self, frame: &frame::GoAway) {
pub fn recv_go_away(&mut self, frame: &frame::GoAway) -> Result<(), RecvError> {
let mut me = self.inner.lock().unwrap();
let me = &mut *me;

Expand All @@ -322,6 +322,10 @@ where
let last_stream_id = frame.last_stream_id();
let err = frame.reason().into();

if actions.recv.max_stream_id() < last_stream_id {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a bit confused with this, until I went digging into recv to read the comments about max_stream_id. Whatcha think if there was a comment right here just saying to the effect of "if a new GOAWAY has a higher stream id than a previous GOAWAY, that's bad"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return Err(RecvError::Connection(Reason::PROTOCOL_ERROR));
}

actions.recv.go_away(last_stream_id);

me.store
Expand All @@ -337,6 +341,8 @@ where
.unwrap();

actions.conn_error = Some(err);

Ok(())
}

pub fn recv_eof(&mut self) {
Expand Down