Skip to content

Commit

Permalink
Unpack a SYN_STREAM before calling the callback. unpack_control only …
Browse files Browse the repository at this point in the history
…handles headers now, renamed.

This didn't get caught by the spec because the stream ID was returned as BinData::Bit31, not Fixnum.
Then the object could be modified after calling the callback.
  • Loading branch information
jonasschneider committed Jan 5, 2012
1 parent 5b74597 commit 98f44ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions lib/spdy/parser.rb
Expand Up @@ -40,9 +40,7 @@ def on_reset(&blk)

private

def unpack_control(pckt, data)
pckt.parse(data)

def handle_headers(pckt)
headers = pckt.uncompressed_data.to_h
if @on_headers && !headers.empty?
@on_headers.call(pckt.header.stream_id.to_i,
Expand All @@ -63,18 +61,21 @@ def try_parse
case pckt.type.to_i
when 1 then # SYN_STREAM
pckt = Control::SynStream.new({:zlib_session => @zlib_session})
pckt.parse(@buffer)

if @on_open
@on_open.call(pckt.header.stream_id,
@on_open.call(pckt.header.stream_id.to_i,
(pckt.associated_to_stream_id.to_i rescue nil),
(pckt.pri.to_i rescue nil))
end
unpack_control(pckt, @buffer)
handle_headers(pckt)

@on_message_complete.call(pckt.header.stream_id) if @on_message_complete && fin?(pckt.header)

when 2 then # SYN_REPLY
pckt = Control::SynReply.new({:zlib_session => @zlib_session})
unpack_control(pckt, @buffer)
pckt.parse(@buffer)
handle_headers(pckt)

@on_message_complete.call(pckt.header.stream_id) if @on_message_complete && fin?(pckt.header)

Expand Down
3 changes: 2 additions & 1 deletion spec/parser_spec.rb
Expand Up @@ -76,7 +76,8 @@
s << SYN_STREAM

order.should == [:open, :headers]


sid.class.should == Fixnum
sid.should == 1
sid2.should == 1
asid.should == 0
Expand Down

0 comments on commit 98f44ca

Please sign in to comment.