Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
plumbing: check that exec-path-prefixed file cmd exists
Browse files Browse the repository at this point in the history
  • Loading branch information
strib committed Aug 2, 2017
1 parent 90a7652 commit 1d2df7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion plumbing/transport/file/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ func prefixExecPath(cmd string) (string, error) {
}
execPath := string(execPathBytes)
execPath = strings.TrimSpace(execPath)
return filepath.Join(execPath, cmd), nil
cmd = filepath.Join(execPath, cmd)

// Make sure it actually exists.
_, err = os.Stat(cmd)
if err != nil {
return "", err
}
return cmd, nil
}

func (r *runner) Command(cmd string, ep transport.Endpoint, auth transport.AuthMethod,
Expand Down
6 changes: 5 additions & 1 deletion plumbing/transport/file/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ func (s *ClientSuite) TestCommand(c *C) {
ep, err := transport.NewEndpoint(filepath.Join("fake", "repo"))
c.Assert(err, IsNil)
var emptyAuth transport.AuthMethod
_, err = runner.Command("git-receieve-pack", ep, emptyAuth)
_, err = runner.Command("git-receive-pack", ep, emptyAuth)
c.Assert(err, IsNil)

// Make sure we get an error for one that doesn't exist.
_, err = runner.Command("git-fake-command", ep, emptyAuth)
c.Assert(os.IsNotExist(err), Equals, true)
}

const bareConfig = `[core]
Expand Down

0 comments on commit 1d2df7c

Please sign in to comment.