From: Russ Cox Date: Wed, 27 Jan 2016 03:13:01 +0000 (-0500) Subject: runtime: fix upper bound on out-of-memory print X-Git-Tag: go1.6rc1~19 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=26397f1383ff02770a62160891e9de349aa1fb92;p=gostls13.git runtime: fix upper bound on out-of-memory print It's possible for arena_start+MaxArena32 to wrap. We do the right thing in the bounds check but not in the print. For #13992 (to fix the print there, not the bug). Change-Id: I4df845d0c03f0f35461b128e4f6765d3ccb71c6d Reviewed-on: https://go-review.googlesource.com/18975 Run-TryBot: Russ Cox Reviewed-by: Austin Clements --- diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 18001bf85e..b520c68df0 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -455,7 +455,11 @@ func (h *mheap) sysAlloc(n uintptr) unsafe.Pointer { } if p < h.arena_start || uintptr(p)+p_size-h.arena_start >= _MaxArena32 { - print("runtime: memory allocated by OS (", hex(p), ") not in usable range [", hex(h.arena_start), ",", hex(h.arena_start+_MaxArena32), ")\n") + top := ^uintptr(0) + if top-h.arena_start > _MaxArena32 { + top = h.arena_start + _MaxArena32 + } + print("runtime: memory allocated by OS (", hex(p), ") not in usable range [", hex(h.arena_start), ",", hex(top), ")\n") sysFree(unsafe.Pointer(p), p_size, &memstats.heap_sys) return nil }