Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go-fuzz: set fd inheritance properly for Go 1.17+ on Windows #330

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ language: go
matrix:
include:
- os: linux
go: "1.16.x"
go: "1.17.x"
- os: linux
go: "1.15.x"
go: "1.16.x"
- os: linux
go: tip
- os: linux
go: tip
env: SET_GO111MODULE=auto
- os: osx
go: "1.16.x"
go: "1.17.x"
- os: osx
go: "1.15.x"
go: "1.16.x"
- os: osx
go: tip
- os: osx
go: tip
env: SET_GO111MODULE=auto
- os: windows
go: "1.16.x"
go: "1.17.x"
- os: windows
go: "1.15.x"
go: "1.16.x"

# Install coreutils for the 'timeout(1)' utility on windows and osx.
before_install:
Expand Down
23 changes: 23 additions & 0 deletions go-fuzz/sys_go116_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2015 go-fuzz project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

//go:build !go1.17
// +build !go1.17

package main

import (
"fmt"
"os"
"os/exec"
"syscall"
)

func setupCommMapping(cmd *exec.Cmd, comm *Mapping, rOut, wIn *os.File) {
syscall.SetHandleInformation(syscall.Handle(comm.mapping), syscall.HANDLE_FLAG_INHERIT, 1)
syscall.SetHandleInformation(syscall.Handle(rOut.Fd()), syscall.HANDLE_FLAG_INHERIT, 1)
syscall.SetHandleInformation(syscall.Handle(wIn.Fd()), syscall.HANDLE_FLAG_INHERIT, 1)
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_COMM_FD=%v", comm.mapping))
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_IN_FD=%v", rOut.Fd()))
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_OUT_FD=%v", wIn.Fd()))
}
31 changes: 31 additions & 0 deletions go-fuzz/sys_go117_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2015 go-fuzz project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

//go:build go1.17
// +build go1.17

package main

import (
"fmt"
"os"
"os/exec"
"syscall"
)

func setupCommMapping(cmd *exec.Cmd, comm *Mapping, rOut, wIn *os.File) {
syscall.SetHandleInformation(syscall.Handle(comm.mapping), syscall.HANDLE_FLAG_INHERIT, 1)
syscall.SetHandleInformation(syscall.Handle(rOut.Fd()), syscall.HANDLE_FLAG_INHERIT, 1)
syscall.SetHandleInformation(syscall.Handle(wIn.Fd()), syscall.HANDLE_FLAG_INHERIT, 1)
// Setting AdditionalInheritedHandles is required in Go 1.17+.
cmd.SysProcAttr = &syscall.SysProcAttr{
AdditionalInheritedHandles: []syscall.Handle{
syscall.Handle(wIn.Fd()),
syscall.Handle(rOut.Fd()),
syscall.Handle(comm.mapping),
},
}
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_COMM_FD=%v", comm.mapping))
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_IN_FD=%v", rOut.Fd()))
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_OUT_FD=%v", wIn.Fd()))
}
11 changes: 0 additions & 11 deletions go-fuzz/sys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
package main

import (
"fmt"
"log"
"os"
"os/exec"
"reflect"
"syscall"
"unsafe"
Expand Down Expand Up @@ -47,12 +45,3 @@ func (m *Mapping) destroy() {
syscall.UnmapViewOfFile(m.addr)
syscall.CloseHandle(m.mapping)
}

func setupCommMapping(cmd *exec.Cmd, comm *Mapping, rOut, wIn *os.File) {
syscall.SetHandleInformation(syscall.Handle(comm.mapping), syscall.HANDLE_FLAG_INHERIT, 1)
syscall.SetHandleInformation(syscall.Handle(rOut.Fd()), syscall.HANDLE_FLAG_INHERIT, 1)
syscall.SetHandleInformation(syscall.Handle(wIn.Fd()), syscall.HANDLE_FLAG_INHERIT, 1)
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_COMM_FD=%v", comm.mapping))
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_IN_FD=%v", rOut.Fd()))
cmd.Env = append(cmd.Env, fmt.Sprintf("GO_FUZZ_OUT_FD=%v", wIn.Fd()))
}