cmd/link: reject invalid -R flag

Reject -R value that is not a power of 2, or less than 4K.

Fixes #62660.

Change-Id: I3fa33c23c25311a93c0accc9acbd1e465789b8c9
Reviewed-on: https://go-review.googlesource.com/c/go/+/528715
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Cherry Mui 2023-09-15 12:02:01 -04:00
parent 5914f6a482
commit 11b08a75cd
1 changed files with 7 additions and 0 deletions

View File

@ -236,6 +236,13 @@ func Main(arch *sys.Arch, theArch Arch) {
Exitf("dynamic linking required on %s; -d flag cannot be used", buildcfg.GOOS)
}
isPowerOfTwo := func(n int64) bool {
return n > 0 && n&(n-1) == 0
}
if *FlagRound != -1 && (*FlagRound < 4096 || !isPowerOfTwo(*FlagRound)) {
Exitf("invalid -R value 0x%x", *FlagRound)
}
checkStrictDups = *FlagStrictDups
switch flagW {