diff options
author | Russ Cox <rsc@golang.org> | 2017-09-13 23:06:54 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2017-09-22 20:08:13 +0000 |
commit | deabc8dc4419b2e65a90ca9f6dc099727b261192 (patch) | |
tree | 66da1ed56db47bcc69e5e5a2a1d69b84b02b43f5 | |
parent | 86b7b52729c2ab898f34bad6df3826ec6c0f61b7 (diff) | |
download | go-deabc8dc4419b2e65a90ca9f6dc099727b261192.tar.gz go-deabc8dc4419b2e65a90ca9f6dc099727b261192.zip |
[dev.boringcrypto.go1.8] crypto/internal/boring: fix detection of tests to allow *.test and *_test
When using the go command, test binaries end in .test,
but when using Bazel, test binaries conventionally end in _test.
Change-Id: Ic4cac8722fd93ae316169f87b321f68e0b71f0c3
Reviewed-on: https://go-review.googlesource.com/63913
Reviewed-by: Adam Langley <agl@golang.org>
Reviewed-on: https://go-review.googlesource.com/65484
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
-rw-r--r-- | src/crypto/internal/boring/boring.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/crypto/internal/boring/boring.go b/src/crypto/internal/boring/boring.go index 97659e4ff7..1dd49fecfb 100644 --- a/src/crypto/internal/boring/boring.go +++ b/src/crypto/internal/boring/boring.go @@ -30,12 +30,17 @@ func Unreachable() { // provided by runtime to avoid os import func runtime_arg0() string +func hasSuffix(s, t string) bool { + return len(s) > len(t) && s[len(s)-len(t):] == t +} + // UnreachableExceptTests marks code that should be unreachable // when BoringCrypto is in use. It panics. func UnreachableExceptTests() { - arg0 := runtime_arg0() - if len(arg0) < 5 || arg0[len(arg0)-5:] != ".test" { - println("ARG0", arg0) + name := runtime_arg0() + // If BoringCrypto ran on Windows we'd need to allow _test.exe and .test.exe as well. + if !hasSuffix(name, "_test") && !hasSuffix(name, ".test") { + println("boringcrypto: unexpected code execution in", name) panic("boringcrypto: invalid code execution") } } |