diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-10-23 22:44:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-23 22:44:45 +0800 |
commit | dcd9fc7ee894700f702f3847d7d2a41d6a009b7e (patch) | |
tree | 76b1d6fdb2a760f3da57bbe566146d1c79ab5a87 /services/cron | |
parent | 4eeea7b30ee5d90ed4e9410ec5c7d0252ada3a3b (diff) | |
download | gitea-dcd9fc7ee894700f702f3847d7d2a41d6a009b7e.tar.gz gitea-dcd9fc7ee894700f702f3847d7d2a41d6a009b7e.zip |
Refactor git command arguments and make all arguments to be safe to be used (#21535)
Follow #21464
Make all git command arguments strictly safe. Most changes are one-to-one replacing, keep all existing logic.
Diffstat (limited to 'services/cron')
-rw-r--r-- | services/cron/tasks_basic.go | 8 | ||||
-rw-r--r-- | services/cron/tasks_extended.go | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/services/cron/tasks_basic.go b/services/cron/tasks_basic.go index 0d7ef4af03..ca35f5be57 100644 --- a/services/cron/tasks_basic.go +++ b/services/cron/tasks_basic.go @@ -12,6 +12,7 @@ import ( git_model "code.gitea.io/gitea/models/git" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/services/auth" "code.gitea.io/gitea/services/migrations" @@ -58,7 +59,12 @@ func registerRepoHealthCheck() { Args: []string{}, }, func(ctx context.Context, _ *user_model.User, config Config) error { rhcConfig := config.(*RepoHealthCheckConfig) - return repo_service.GitFsck(ctx, rhcConfig.Timeout, rhcConfig.Args) + // the git args are set by config, they can be safe to be trusted + args := make([]git.CmdArg, 0, len(rhcConfig.Args)) + for _, arg := range rhcConfig.Args { + args = append(args, git.CmdArg(arg)) + } + return repo_service.GitFsck(ctx, rhcConfig.Timeout, args) }) } diff --git a/services/cron/tasks_extended.go b/services/cron/tasks_extended.go index 04b9560be3..c730477cbd 100644 --- a/services/cron/tasks_extended.go +++ b/services/cron/tasks_extended.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/system" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/updatechecker" repo_service "code.gitea.io/gitea/services/repository" @@ -60,7 +61,12 @@ func registerGarbageCollectRepositories() { Args: setting.Git.GCArgs, }, func(ctx context.Context, _ *user_model.User, config Config) error { rhcConfig := config.(*RepoHealthCheckConfig) - return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, rhcConfig.Args...) + // the git args are set by config, they can be safe to be trusted + args := make([]git.CmdArg, 0, len(rhcConfig.Args)) + for _, arg := range rhcConfig.Args { + args = append(args, git.CmdArg(arg)) + } + return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, args...) }) } |