]> Cypherpunks.ru repositories - gostls13.git/commit
runtime: don't crash on nil pointers in checkptrAlignment
authorMatthew Dempsky <mdempsky@google.com>
Wed, 28 Jul 2021 01:30:38 +0000 (18:30 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 28 Jul 2021 03:27:13 +0000 (03:27 +0000)
commitb39e0f461c099abf98f5a8c81d58d32d9a765a03
tree3700f94556618f11f37a64e5298cf554b3d90597
parent7cd10c1149e51a9d2f0868babaf66b8091b9c0b9
runtime: don't crash on nil pointers in checkptrAlignment

Ironically, checkptrAlignment had a latent case of bad pointer
arithmetic: if ptr is nil, then `add(ptr, size-1)` might produce an
illegal pointer value.

The fix is to simply check for nil at the top of checkptrAlignment,
and short-circuit if so.

This CL also adds a more explicit bounds check in checkptrStraddles,
rather than relying on `add(ptr, size-1)` to wrap around. I don't
think this is necessary today, but it seems prudent to be careful.

Fixes #47430.

Change-Id: I5c50b2f7f41415dbebbd803e1b8e7766ca95e1fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/338029
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/checkptr.go
src/runtime/checkptr_test.go
src/runtime/testdata/testprog/checkptr.go