From 53635ba538fb41bbfd38b70282cd6d59e693c0b3 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Mon, 26 Dec 2016 20:42:00 +0100 Subject: [PATCH] Fixed panic due to 0-length buffers being passed to io.CopyBuffer --- caddyhttp/proxy/reverseproxy.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/caddyhttp/proxy/reverseproxy.go b/caddyhttp/proxy/reverseproxy.go index 050e7fb9..49df1603 100644 --- a/caddyhttp/proxy/reverseproxy.go +++ b/caddyhttp/proxy/reverseproxy.go @@ -253,7 +253,7 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request, } func (rp *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) { - buf := bufferPool.Get() + buf := bufferPool.Get().([]byte) defer bufferPool.Put(buf) if rp.FlushInterval != 0 { @@ -268,7 +268,10 @@ func (rp *ReverseProxy) copyResponse(dst io.Writer, src io.Reader) { dst = mlw } } - io.CopyBuffer(dst, src, buf.([]byte)) + + // `CopyBuffer` only uses `buf` up to it's length and + // panics if it's 0 => Extend it's length up to it's capacity. + io.CopyBuffer(dst, src, buf[:cap(buf)]) } // skip these headers if they already exist.