Skip to content

Commit

Permalink
MFH: r534921
Browse files Browse the repository at this point in the history
www/gitea: Fix viewing of branches with a slash in the name

An issue[0] was filed upstream in January that branches with a slash in
their name (e.g. stable/11) result in a 500 error when attempting to view
them.

I tracked down the issue to the fact that read(2) on a directory fd in
FreeBSD will actually succeed, while it will not on Linux/other OS. I have
filed a PR[1] with go-git to remedy the problem there, and then we
(hopefully) convince gitea maintainers to accept the patch as well once it's
upstreamed.

The attached patch brings it into the ports tree as well, so that FreeBSD
users can more immediately get the fix. It should still apply to the version
in 2020Q2, more or less, with version numbers changed to protect the
innocent.

[0] go-gitea/gitea#9938
[1] go-git/go-git#39

PR:		245863
Approved by:	<stb lassitu de> (maintainer)
Aoorived by:	koobs (mentor, ports)

Approved by:	ports-secteam (blanket: minor bugfix patch)
  • Loading branch information
kevans91 committed May 11, 2020
1 parent 464f81b commit 1d50d5c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion www/gitea/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
PORTNAME= gitea
DISTVERSIONPREFIX= v
DISTVERSION= 1.11.4
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= www
MASTER_SITES= https://github.com/go-gitea/gitea/releases/download/${DISTVERSIONPREFIX}${DISTVERSION}/
DISTNAME= gitea-src-${DISTVERSION}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This patch fixes a bug where attempting to view branches with a / in the name
# would return an HTTP 500 Internal Server Error. The underlying issue ended up
# being that go-git implicitly relied on read() of a dirfd to succeed, so for a
# branch named "stable/11" it would stop and assume "stable" was the ref, but it
# was really just a directory.

# This patch was accepted upstream here:
# https://github.com/go-git/go-git/pull/39
# go-gitea is expected to merge it when go-git creates a new release for them to
# import, and this patch can silently go away as soon as it conflicts.

--- vendor/github.com/go-git/go-git/v5/storage/filesystem/dotgit/dotgit.go.orig 2020-04-01 17:02:04 UTC
+++ vendor/github.com/go-git/go-git/v5/storage/filesystem/dotgit/dotgit.go
@@ -57,6 +57,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.
@@ -926,6 +929,14 @@ func (d *DotGit) addRefFromHEAD(refs *[]*plumbing.Refe

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

0 comments on commit 1d50d5c

Please sign in to comment.