MCPcopy Create free account
hub / github.com/cli/cli / checkBuildsDir

Function checkBuildsDir

script/ghmock/run.go:459–476  ·  view source on GitHub ↗

checkBuildsDir checks that a binary is inside buildsDir, after following symlinks, so a link can't point outside it.

(name, abs string)

Source from the content-addressed store, hash-verified

457// checkBuildsDir checks that a binary is inside buildsDir, after following
458// symlinks, so a link can't point outside it.
459func checkBuildsDir(name, abs string) error {
460 if buildsDir == "" {
461 return nil
462 }
463 root, err := filepath.EvalSymlinks(buildsDir)
464 if err != nil {
465 return err
466 }
467 resolved, err := filepath.EvalSymlinks(abs)
468 if err != nil {
469 return err
470 }
471 rel, err := filepath.Rel(root, resolved)
472 if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
473 return fmt.Errorf("%s isn't a gh build in %s, and this ghmock only runs those", name, buildsDir)
474 }
475 return nil
476}
477
478// writeGHConfig writes gh's config the way gh auth login --insecure-storage
479// leaves it, logged in to host as fakeUser with fakeToken. That's where a

Callers 1

resolveBinaryFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected