Skip to content

Latest commit

History

History
51 lines (35 loc) 路 998 Bytes

README.md

File metadata and controls

51 lines (35 loc) 路 998 Bytes

Looker

馃攳 find app path and print it.

A alternative package to exec.LookPath().

The problem

The following code, relatively common approach to running external commands has a vulnerability on Windows:

import "os/exec"

func gitAdd() error {
    cmd := exec.Command("git", "add", "Formula")
    return cmd.Run()
}

Searching the current directory (surprising behavior) before searching folders listed in the PATH environment variable (expected behavior) seems to be intended in Go and unlikely to be changed go#38736

Install

go get -v github.com/abdfnx/looker@v0.1.0

Example:

import (
    "os/exec"

    "github.com/abdfnx/looker"
)

func gitAdd() error {
    gitPath, err := looker.LookPath("git")

    if err != nil {
        return err
    }

    cmd := exec.Command(gitPath, "add", "Formula")
    return cmd.Run()
}