]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: reject invalid -R flag
authorCherry Mui <cherryyz@google.com>
Fri, 15 Sep 2023 16:02:01 +0000 (12:02 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 15 Sep 2023 17:22:06 +0000 (17:22 +0000)
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>

src/cmd/link/internal/ld/main.go

index b978cfc7d491900412baaa8e54522ae9ccabb37a..589b5065fd794443d230fe611d0f1dc7486f7f29 100644 (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 {