Skip to content

Commit a95c5d3

Browse files
dagoodqmuntal
authored andcommitted
cmd/link/internal/loadpe: fix xrels search "not found" detection
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 <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: Quim Muntal <[email protected]> Reviewed-by: Than McIntosh <[email protected]> Reviewed-by: Quim Muntal <[email protected]>
1 parent 3f04f95 commit a95c5d3

File tree

1 file changed

+4
-3
lines changed
  • src/cmd/link/internal/loadpe

1 file changed

+4
-3
lines changed

src/cmd/link/internal/loadpe/seh.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,17 @@ func findHandlerInXDataAMD64(ldr *loader.Loader, xsym sym.LoaderSym, add int64)
9090
// unless it is chained, but we will handle this case later.
9191
targetOff := add + unwStaticDataSize*(1+int64(codes))
9292
xrels := ldr.Relocs(xsym)
93-
idx := sort.Search(xrels.Count(), func(i int) bool {
93+
xrelsCount := xrels.Count()
94+
idx := sort.Search(xrelsCount, func(i int) bool {
9495
return int64(xrels.At(i).Off()) >= targetOff
9596
})
96-
if idx == 0 {
97+
if idx == xrelsCount {
9798
return 0
9899
}
99100
if isChained {
100101
// The third relocations references the next .xdata entry in the chain, recurse.
101102
idx += 2
102-
if idx >= xrels.Count() {
103+
if idx >= xrelsCount {
103104
return 0
104105
}
105106
r := xrels.At(idx)

0 commit comments

Comments
 (0)