aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/objdump
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2020-03-11 13:36:42 -0400
committerDavid Chase <drchase@google.com>2020-03-12 20:40:54 +0000
commit29b36a88ab0b179c140612e7c907042b2a388587 (patch)
treef7cff4218c96143ba7f1b98c827db3f6ac321117 /src/cmd/objdump
parente221a75deab7843d5414154000f5bea7abcb60c3 (diff)
downloadgo-29b36a88ab0b179c140612e7c907042b2a388587.tar.gz
go-29b36a88ab0b179c140612e7c907042b2a388587.zip
cmd/objdump: guard against out-of-range lines from directives.
//line bogo.go:9999999 will cause 'go tool objdump' to crash unless bogo.go has that many lines. Guard the array index and return innocuous values (nil, nil) from the file cache. Fixes #36683 Change-Id: I4a9f8444dc611654d270cc876e8848dfd2f84770 Reviewed-on: https://go-review.googlesource.com/c/go/+/223081 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/cmd/objdump')
-rw-r--r--src/cmd/objdump/objdump_test.go13
-rw-r--r--src/cmd/objdump/testdata/fmthello.go2
2 files changed, 12 insertions, 3 deletions
diff --git a/src/cmd/objdump/objdump_test.go b/src/cmd/objdump/objdump_test.go
index 0c2adbdb94..7ed32cf3c2 100644
--- a/src/cmd/objdump/objdump_test.go
+++ b/src/cmd/objdump/objdump_test.go
@@ -106,8 +106,11 @@ func testDisasm(t *testing.T, printCode bool, flags ...string) {
hello := filepath.Join(tmp, fmt.Sprintf("hello-%x.exe", hash))
args := []string{"build", "-o", hello}
args = append(args, flags...)
- args = append(args, "testdata/fmthello.go")
- out, err := exec.Command(testenv.GoToolPath(t), args...).CombinedOutput()
+ args = append(args, "fmthello.go")
+ cmd := exec.Command(testenv.GoToolPath(t), args...)
+ cmd.Dir = "testdata" // "Bad line" bug #36683 is sensitive to being run in the source directory
+ t.Logf("Running %v", cmd.Args)
+ out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("go build fmthello.go: %v\n%s", err, out)
}
@@ -139,7 +142,11 @@ func testDisasm(t *testing.T, printCode bool, flags ...string) {
args = append([]string{"-S"}, args...)
}
- out, err = exec.Command(exe, args...).CombinedOutput()
+ cmd = exec.Command(exe, args...)
+ cmd.Dir = "testdata" // "Bad line" bug #36683 is sensitive to being run in the source directory
+ out, err = cmd.CombinedOutput()
+ t.Logf("Running %v", cmd.Args)
+
if err != nil {
t.Fatalf("objdump fmthello.exe: %v\n%s", err, out)
}
diff --git a/src/cmd/objdump/testdata/fmthello.go b/src/cmd/objdump/testdata/fmthello.go
index fd16ebee1b..c8d82466dc 100644
--- a/src/cmd/objdump/testdata/fmthello.go
+++ b/src/cmd/objdump/testdata/fmthello.go
@@ -5,6 +5,8 @@ import "fmt"
func main() {
Println("hello, world")
if flag {
+//line fmthello.go:999999
+ Println("bad line")
for {
}
}