aboutsummaryrefslogtreecommitdiff
path: root/src/debug
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2024-07-26 13:26:12 -0400
committerGopher Robot <gobot@golang.org>2024-07-29 15:34:55 +0000
commitfd7d5a6e6c56c79059b5ce4bb9f38897ad752b3c (patch)
tree51ae8016c0ba2e4e70cb990b8395bccd30c05520 /src/debug
parent28aed4015ee7ba85b29007d685de9150e01a9acd (diff)
downloadgo-fd7d5a6e6c56c79059b5ce4bb9f38897ad752b3c.tar.xz
debug/buildinfo: add test for malformed strings
Updates #68592. Change-Id: I00c6c740ca0bdd19af24e08a219ec3c90196097e Reviewed-on: https://go-review.googlesource.com/c/go/+/601458 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/debug')
-rw-r--r--src/debug/buildinfo/buildinfo_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/debug/buildinfo/buildinfo_test.go b/src/debug/buildinfo/buildinfo_test.go
index 9f9756a22c..e78099da21 100644
--- a/src/debug/buildinfo/buildinfo_test.go
+++ b/src/debug/buildinfo/buildinfo_test.go
@@ -134,6 +134,22 @@ func TestReadFile(t *testing.T) {
}
}
+ damageStringLen := func(t *testing.T, name string) {
+ data, err := os.ReadFile(name)
+ if err != nil {
+ t.Fatal(err)
+ }
+ i := bytes.Index(data, []byte("\xff Go buildinf:"))
+ if i < 0 {
+ t.Fatal("Go buildinf not found")
+ }
+ verLen := data[i+32:]
+ binary.PutUvarint(verLen, 16<<40) // 16TB ought to be enough for anyone.
+ if err := os.WriteFile(name, data, 0666); err != nil {
+ t.Fatal(err)
+ }
+ }
+
goVersionRe := regexp.MustCompile("(?m)^go\t.*\n")
buildRe := regexp.MustCompile("(?m)^build\t.*\n")
cleanOutputForComparison := func(got string) string {
@@ -194,6 +210,15 @@ func TestReadFile(t *testing.T) {
wantErr: "not a Go executable",
},
{
+ name: "invalid_str_len",
+ build: func(t *testing.T, goos, goarch, buildmode string) string {
+ name := buildWithModules(t, goos, goarch, buildmode)
+ damageStringLen(t, name)
+ return name
+ },
+ wantErr: "not a Go executable",
+ },
+ {
name: "valid_gopath",
build: buildWithGOPATH,
want: "go\tGOVERSION\n" +