]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix upper bound on out-of-memory print
authorRuss Cox <rsc@golang.org>
Wed, 27 Jan 2016 03:13:01 +0000 (22:13 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 27 Jan 2016 04:58:44 +0000 (04:58 +0000)
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 <rsc@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/malloc.go

index 18001bf85ec64c383ebb563795db8ae25907d687..b520c68df0810c230ced3e68338420eec6a1fcb4 100644 (file)
@@ -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
        }