Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2023-04-20 13:38:50 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2023-05-02 12:16:06 +0300
commit93181a27a9b2810eac4abc9be2d94be5986a28db (patch)
treeff37daad4aa67af13d12a31062c38c33ddca8430
parent32cc3ce13b7b8bf42dc6eb5c342fd6f190952c4b (diff)
repository: Properly validate source repo passed to CreateFork
While we verify that the caller indeed passes a source repository to CreateFork, we don't verify that it also contains sensible data. Fix this by validating it via `service.ValidateRepository()`.
-rw-r--r--internal/gitaly/service/repository/create_fork.go10
-rw-r--r--internal/gitaly/service/repository/create_fork_test.go2
2 files changed, 6 insertions, 6 deletions
diff --git a/internal/gitaly/service/repository/create_fork.go b/internal/gitaly/service/repository/create_fork.go
index bb172eac5..d10307639 100644
--- a/internal/gitaly/service/repository/create_fork.go
+++ b/internal/gitaly/service/repository/create_fork.go
@@ -13,16 +13,16 @@ import (
)
func (s *server) CreateFork(ctx context.Context, req *gitalypb.CreateForkRequest) (*gitalypb.CreateForkResponse, error) {
- targetRepository := req.Repository
- sourceRepository := req.SourceRepository
-
- if sourceRepository == nil {
- return nil, structerr.NewInvalidArgument("empty SourceRepository")
+ if err := service.ValidateRepository(req.GetSourceRepository()); err != nil {
+ return nil, structerr.NewInvalidArgument("validating source repository: %w", err)
}
if err := service.ValidateRepository(req.GetRepository()); err != nil {
return nil, structerr.NewInvalidArgument("%w", err)
}
+ targetRepository := req.Repository
+ sourceRepository := req.SourceRepository
+
if err := repoutil.Create(ctx, s.locator, s.gitCmdFactory, s.txManager, targetRepository, func(repo *gitalypb.Repository) error {
targetPath, err := s.locator.GetPath(repo)
if err != nil {
diff --git a/internal/gitaly/service/repository/create_fork_test.go b/internal/gitaly/service/repository/create_fork_test.go
index ff68a9051..a1352e1eb 100644
--- a/internal/gitaly/service/repository/create_fork_test.go
+++ b/internal/gitaly/service/repository/create_fork_test.go
@@ -283,7 +283,7 @@ func TestCreateFork_validate(t *testing.T) {
if testhelper.IsPraefectEnabled() {
return status.Error(codes.AlreadyExists, "route repository creation: reserve repository id: repository already exists")
}
- return status.Error(codes.InvalidArgument, "empty SourceRepository")
+ return status.Error(codes.InvalidArgument, "validating source repository: empty Repository")
}(),
},
} {