-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
Description
Calling (*bufio.Writer).Flush panics if (*bufio.Writer).Reset is called with a nil io.Writer, then (*bufio.Writer).Write is called before the flush. This seems like an unlikely scenario but it has been seen on moby/moby#10228. Though the use case may be invalid, the call should not panic.
The following code reproduces the issue:
package main
import (
"bufio"
"bytes"
)
func main() {
var buf bytes.Buffer
wr := bufio.NewWriter(&buf)
wr.Reset(nil)
wr.Write([]byte("asdf"))
wr.Flush()
}Running the above results in the following panic:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x20 pc=0x3366a]
goroutine 1 [running]:
bufio.(*Writer).flush(0x2080f0000, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:530 +0xda
bufio.(*Writer).Flush(0x2080f0000, 0x0, 0x0)
/usr/local/go/src/bufio/bufio.go:519 +0x3a
main.main()
/tmp/bug.go:13 +0x10b
goroutine 2 [runnable]:
runtime.forcegchelper()
/usr/local/go/src/runtime/proc.go:90
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1
goroutine 3 [runnable]:
runtime.bgsweep()
/usr/local/go/src/runtime/mgc0.go:82
runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1
exit status 2
This was reproduced with Go 1.4.1 on Mac OS X 10.9 but has been experienced in other versions.
Reactions are currently unavailable