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

Switch execution to x/sys/execabs for windows security fix #255

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions conn_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"errors"
"fmt"
"os"
"os/exec"

"golang.org/x/sys/execabs"
)

const defaultSystemBusAddress = "unix:path=/opt/local/var/run/dbus/system_bus_socket"

func getSessionBusPlatformAddress() (string, error) {
cmd := exec.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET")
cmd := execabs.Command("launchctl", "getenv", "DBUS_LAUNCHD_SESSION_BUS_SOCKET")
b, err := cmd.CombinedOutput()

if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions conn_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"os/user"
"path"
"strings"

"golang.org/x/sys/execabs"
)

var execCommand = exec.Command
var execCommand = execabs.Command

func getSessionBusPlatformAddress() (string, error) {
cmd := execCommand("dbus-launch")
cmd := execabs.Command("dbus-launch")
b, err := cmd.CombinedOutput()

if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions exec_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package dbus
import (
"fmt"
"os"
"os/exec"
"strconv"
"testing"

"golang.org/x/sys/execabs"
)

// How to mock exec.Command for unit tests
Expand All @@ -14,10 +15,10 @@ import (
var mockedExitStatus = 0
var mockedStdout string

func fakeExecCommand(command string, args ...string) *exec.Cmd {
func fakeExecCommand(command string, args ...string) *execabs.Cmd {
cs := []string{"-test.run=TestExecCommandHelper", "--", command}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
cmd := execabs.Command(os.Args[0], cs...)
es := strconv.Itoa(mockedExitStatus)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1",
"STDOUT=" + mockedStdout,
Expand All @@ -43,7 +44,7 @@ DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-0SO9YZUBGA,guid=ac22f2f3b9d2284
DBUS_SESSION_BUS_PID=7620
DBUS_SESSION_BUS_WINDOWID=16777217`
execCommand = fakeExecCommand
defer func() { execCommand = exec.Command }()
defer func() { execCommand = execabs.Command }()
expOut := ""
expErr := "dbus: couldn't determine address of session bus"

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/godbus/dbus/v5

go 1.12

require golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5 changes: 3 additions & 2 deletions transport_nonce_tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"bufio"
"io/ioutil"
"os"
"os/exec"
"testing"

"golang.org/x/sys/execabs"
)

func TestTcpNonceConnection(t *testing.T) {
Expand Down Expand Up @@ -47,7 +48,7 @@ func startDaemon(t *testing.T, config string) (string, *os.Process) {
t.Fatal(err)
}

cmd := exec.Command("dbus-daemon", "--nofork", "--print-address", "--config-file", cfg.Name())
cmd := execabs.Command("dbus-daemon", "--nofork", "--print-address", "--config-file", cfg.Name())
cmd.Stderr = os.Stderr
out, err := cmd.StdoutPipe()
if err != nil {
Expand Down