checkBuildsDir checks that a binary is inside buildsDir, after following symlinks, so a link can't point outside it.
(name, abs string)
| 457 | // checkBuildsDir checks that a binary is inside buildsDir, after following |
| 458 | // symlinks, so a link can't point outside it. |
| 459 | func 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 |