SlyMarbo / spdy

[deprecated] A full-featured SPDY library for the Go language.
BSD 2-Clause "Simplified" License
116 stars 13 forks source link

Unitialized buffer panicing on read of http.Request.Body #34

Closed pabbott0 closed 10 years ago

pabbott0 commented 10 years ago

serverStreamV3.ReceiveFrame is trying to copy the frame to s.requestBody before it is initialized. It looks like that buffer is initialized in serverStreamV3.Run, however Run is called AFTER ReceiveFrame.

I added code to ReceiveFrame to conditionally init s.requestBody, which worked, but then serverStreamV3.Run was called, blowing the contents of s.requestBody away. I then removed the code from Run that initialized the buffer, and things started to work. I don't know the s.requestBody lifecycle well enough to reliably tell if this is the correct way to fix the issue or not

Stack trace below. The debug statement on top contains the contents of the frame ("test") and the contents of s.requestBody (nil)

(spdy) 2014/02/17 18:05:42 spdy3_server_stream.go:179: setting req body  [116 101 115 116] <nil>
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x68 pc=0x41ba385]

goroutine 13 [running]:
runtime.panic(0x43f1280, 0x4858d39)
    /usr/local/Cellar/go/1.2/libexec/src/pkg/runtime/panic.c:266 +0xb6
bytes.(*Buffer).Write(0x0, 0xc210000b60, 0x4, 0x4, 0x4348000, ...)
    /usr/local/Cellar/go/1.2/libexec/src/pkg/bytes/buffer.go:126 +0x35
github.com/SlyMarbo/spdy.(*serverStreamV3).ReceiveFrame(0xc21007e080, 0x4b188c8, 0xc21010ee60, 0x0, 0x0)
    /Users/liver/devel/go/src/github.com/SlyMarbo/spdy/spdy3_server_stream.go:180 +0x5ac
github.com/SlyMarbo/spdy.(*connV3).handleClientData(0xc2100ef540, 0xc21010ee60)
    /Users/liver/devel/go/src/github.com/SlyMarbo/spdy/spdy3_conn.go:484 +0x459
github.com/SlyMarbo/spdy.(*connV3).processFrame(0xc2100ef540, 0x4b188c8, 0xc21010ee60, 0x1)
    /Users/liver/devel/go/src/github.com/SlyMarbo/spdy/spdy3_conn.go:1177 +0xcbd
github.com/SlyMarbo/spdy.(*connV3).readFrames(0xc2100ef540)
    /Users/liver/devel/go/src/github.com/SlyMarbo/spdy/spdy3_conn.go:1224 +0x4c5
created by github.com/SlyMarbo/spdy.(*connV3).Run
    /Users/liver/devel/go/src/github.com/SlyMarbo/spdy/spdy3_conn.go:393 +0xb3
SlyMarbo commented 10 years ago

Thanks for the bug report. This should be fixed now. I've moved the initialisation to Conn.newStream and then checked it's fine in Stream.run().

pabbott0 commented 10 years ago

Works great, thanks for the quick fix.