aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/dotgit/dotgit.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2020-04-24 14:05:39 +0200
committerGitHub <noreply@github.com>2020-04-24 14:05:39 +0200
commitc9533a6f9f3a6edd0fb7c8c161d4016a6af26bc3 (patch)
tree2046075da6803e110c9d6272d0f49f9f7020d7d3 /storage/filesystem/dotgit/dotgit.go
parent218a744b6995a89f5c322aa58e79138d65392ea6 (diff)
parent63967abe62ecba22a792e728f1af509f3604881f (diff)
downloadgo-git-c9533a6f9f3a6edd0fb7c8c161d4016a6af26bc3.tar.gz
Merge pull request #39 from kevans91/fixread
storage/filesystem: dotgit, sanity check provided reference path
Diffstat (limited to 'storage/filesystem/dotgit/dotgit.go')
-rw-r--r--storage/filesystem/dotgit/dotgit.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go
index 503ce18..8c3896b 100644
--- a/storage/filesystem/dotgit/dotgit.go
+++ b/storage/filesystem/dotgit/dotgit.go
@@ -59,6 +59,9 @@ var (
// targeting a non-existing object. This usually means the repository
// is corrupt.
ErrSymRefTargetNotFound = errors.New("symbolic reference target not found")
+ // ErrIsDir is returned when a reference file is attempting to be read,
+ // but the path specified is a directory.
+ ErrIsDir = errors.New("reference path is a directory")
)
// Options holds configuration for the storage.
@@ -946,6 +949,14 @@ func (d *DotGit) addRefFromHEAD(refs *[]*plumbing.Reference) error {
func (d *DotGit) readReferenceFile(path, name string) (ref *plumbing.Reference, err error) {
path = d.fs.Join(path, d.fs.Join(strings.Split(name, "/")...))
+ st, err := d.fs.Stat(path)
+ if err != nil {
+ return nil, err
+ }
+ if st.IsDir() {
+ return nil, ErrIsDir
+ }
+
f, err := d.fs.Open(path)
if err != nil {
return nil, err