cmd/buildid: reject rewriting legacy buildids

This resolves legacy go binaries crashing the buildid tool when the -w flag is specified.

Fixes #50809

Change-Id: I55a866f285a3c2cebcf2cdbb9cc30e5078e1d18f
GitHub-Last-Rev: 7169a58fd7
GitHub-Pull-Request: golang/go#53163
Reviewed-on: https://go-review.googlesource.com/c/go/+/409535
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
Stephen Eckels 2022-06-04 20:39:36 +00:00 committed by Gopher Robot
parent 47f806ce81
commit 66cbf67345

View file

@ -53,6 +53,11 @@ func main() {
log.Fatal(err)
}
// <= go 1.7 doesn't embed the contentID or actionID, so no slash is present
if !strings.Contains(id, "/") {
log.Fatalf("%s: build ID is a legacy format...binary too old for this tool", file)
}
newID := id[:strings.LastIndex(id, "/")] + "/" + buildid.HashToString(hash)
if len(newID) != len(id) {
log.Fatalf("%s: build ID length mismatch %q vs %q", file, id, newID)