diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2016-09-24 17:07:35 +0200 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2016-09-25 12:22:04 +0000 |
commit | 38765eba739461e5c5dc463860c62daee2eef4ee (patch) | |
tree | 78cb9825e6e5da296d8dfa2240aea1df36a20228 /src/runtime/race.go | |
parent | 9f1c78781b320b6d7cf83378b857c1168cb7fd0f (diff) | |
download | go-38765eba739461e5c5dc463860c62daee2eef4ee.tar.gz go-38765eba739461e5c5dc463860c62daee2eef4ee.zip |
runtime/race: don't crash on invalid PCs
Currently raceSymbolizeCode uses funcline, which is internal runtime
function which crashes on incorrect PCs. Use FileLine instead,
it is public and does not crash on invalid data.
Note: FileLine returns "?" file on failure. That string is not NUL-terminated,
so we need to additionally check what FileLine returns.
Fixes #17190
Change-Id: Ic6fbd4f0e68ddd52e9b2dd25e625b50adcb69a98
Reviewed-on: https://go-review.googlesource.com/29714
Run-TryBot: Dmitry Vyukov <dvyukov@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/race.go')
-rw-r--r-- | src/runtime/race.go | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/runtime/race.go b/src/runtime/race.go index 42da936ddb..6f24e09925 100644 --- a/src/runtime/race.go +++ b/src/runtime/race.go @@ -91,23 +91,23 @@ func racecallback(cmd uintptr, ctx unsafe.Pointer) { } func raceSymbolizeCode(ctx *symbolizeCodeContext) { - f := findfunc(ctx.pc) - if f == nil { - ctx.fn = &qq[0] - ctx.file = &dash[0] - ctx.line = 0 - ctx.off = ctx.pc - ctx.res = 1 - return + f := FuncForPC(ctx.pc) + if f != nil { + file, line := f.FileLine(ctx.pc) + if line != 0 { + ctx.fn = cfuncname(f.raw()) + ctx.line = uintptr(line) + ctx.file = &bytes(file)[0] // assume NUL-terminated + ctx.off = ctx.pc - f.Entry() + ctx.res = 1 + return + } } - - ctx.fn = cfuncname(f) - file, line := funcline(f, ctx.pc) - ctx.line = uintptr(line) - ctx.file = &bytes(file)[0] // assume NUL-terminated - ctx.off = ctx.pc - f.entry + ctx.fn = &qq[0] + ctx.file = &dash[0] + ctx.line = 0 + ctx.off = ctx.pc ctx.res = 1 - return } type symbolizeDataContext struct { |