]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link/internal/loadpe: fix xrels search "not found" detection
authorDavis Goodin <dagood@microsoft.com>
Thu, 16 Nov 2023 18:20:56 +0000 (10:20 -0800)
committerQuim Muntal <quimmuntal@gmail.com>
Thu, 16 Nov 2023 20:37:59 +0000 (20:37 +0000)
Fixes findHandlerInXDataAMD64 to handle the return value of sort.Search
when the search fails to find anything. Otherwise, the value may later
be used as an index, causing an out of range error.

Fixes #64200

Change-Id: I4f92e76b3f4d4d5dbe5cbc707f808298c580afe1
Reviewed-on: https://go-review.googlesource.com/c/go/+/543076
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Quim Muntal <quimmuntal@gmail.com>
src/cmd/link/internal/loadpe/seh.go

index a97595c10c66cebf0b31d25df199a87f24af22ad..0e2cda21ddc551eb3210642e77d5ff25b18aace4 100644 (file)
@@ -90,16 +90,17 @@ func findHandlerInXDataAMD64(ldr *loader.Loader, xsym sym.LoaderSym, add int64)
        // unless it is chained, but we will handle this case later.
        targetOff := add + unwStaticDataSize*(1+int64(codes))
        xrels := ldr.Relocs(xsym)
-       idx := sort.Search(xrels.Count(), func(i int) bool {
+       xrelsCount := xrels.Count()
+       idx := sort.Search(xrelsCount, func(i int) bool {
                return int64(xrels.At(i).Off()) >= targetOff
        })
-       if idx == 0 {
+       if idx == xrelsCount {
                return 0
        }
        if isChained {
                // The third relocations references the next .xdata entry in the chain, recurse.
                idx += 2
-               if idx >= xrels.Count() {
+               if idx >= xrelsCount {
                        return 0
                }
                r := xrels.At(idx)