Skip to content

Commit

Permalink
Merge pull request #11 from trimble-oss/revert_exe
Browse files Browse the repository at this point in the history
Reverting attempt to address filehandle leak.
  • Loading branch information
joel-rieke committed Jan 31, 2024
2 parents 9ef0b5b + a443c6b commit 69d204e
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions cap/tap/tap_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import (
"io"
"net"
"os"
"os/exec"
"os/signal"
"os/user"
"strconv"
"strings"
"syscall"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -93,28 +91,17 @@ func Tap(target string, expectedSha256 string, group string, skipPathControls bo
continue
}

// Workaround linux file handle leak in readlink lib...
cmd := exec.Command("/usr/bin/readlink", "-f", "/proc/"+strconv.Itoa(int(cred.Pid))+"/exe")
pathBytes, linkErr := cmd.Output()

if linkErr != nil {
os.Exit(-1)
}
path := strings.TrimSpace(string(pathBytes))
// End workaround...

// path, linkErr := os.Readlink("/proc/" + strconv.Itoa(int(cred.Pid)) + "/exe")
// pathBytes, exePathErr := cmd.Output()
path, linkErr := os.Readlink("/proc/" + strconv.Itoa(int(cred.Pid)) + "/exe")

if !skipPathControls && linkErr != nil {
conn.Close()
continue
}

// 2nd check.
if skipPathControls || string(path) == target {
if skipPathControls || path == target {
// 3rd check.
peerExe, err := os.Open(string(path))
peerExe, err := os.Open(path)
if !skipPathControls && err != nil {
conn.Close()
continue
Expand Down

0 comments on commit 69d204e

Please sign in to comment.