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] https://github.com/go-gitea/gitea/issues/9938
[1] https://github.com/go-git/go-git/pull/39

PR:		245863
Approved by:	<stb lassitu de> (maintainer)
Aoorived by:	koobs (mentor, ports)
MFH:		2020Q2 (minor bugfix patch)
This commit is contained in:
Kyle Evans 2020-05-11 16:52:28 +00:00
parent 8f7615b355
commit ceecbb4c57
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=534921
2 changed files with 39 additions and 0 deletions

View File

@ -3,6 +3,7 @@
PORTNAME= gitea
DISTVERSIONPREFIX= v
DISTVERSION= 1.11.5
PORTREVISION= 1
CATEGORIES= www
MASTER_SITES= https://github.com/go-gitea/gitea/releases/download/${DISTVERSIONPREFIX}${DISTVERSION}/
DISTNAME= gitea-src-${DISTVERSION}

View File

@ -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