runtime: fix buffer overflow in make(chan)

On 32-bits one can arrange make(chan) params so that
the chan buffer gives you access to whole memory.

LGTM=r
R=golang-codereviews, r
CC=bradfitz, golang-codereviews, iant, khr
https://golang.org/cl/50250045
This commit is contained in:
Dmitriy Vyukov 2014-01-28 22:37:35 +04:00
parent ce884036d2
commit d409e44cfb
1 changed files with 1 additions and 1 deletions

View File

@ -104,7 +104,7 @@ runtime·makechan_c(ChanType *t, int64 hint)
if((sizeof(*c)%MAXALIGN) != 0 || elem->align > MAXALIGN)
runtime·throw("makechan: bad alignment");
if(hint < 0 || (intgo)hint != hint || (elem->size > 0 && hint > MaxMem / elem->size))
if(hint < 0 || (intgo)hint != hint || (elem->size > 0 && hint > (MaxMem - sizeof(*c)) / elem->size))
runtime·panicstring("makechan: size out of range");
// allocate memory in one call