]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.boringcrypto] crypto/internal/boring: fix detection of tests to allow *.test...
authorRuss Cox <rsc@golang.org>
Thu, 14 Sep 2017 03:06:54 +0000 (23:06 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 18 Sep 2017 00:27:12 +0000 (00:27 +0000)
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>
src/crypto/internal/boring/boring.go

index 97659e4ff77b89c63671c675531b5d92f1ea7b85..1dd49fecfbae4ddd339db11f8dfbcb2b2d0d760f 100644 (file)
@@ -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")
        }
 }