diff options
author | Giteabot <teabot@gitea.io> | 2024-09-24 09:58:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-24 01:58:58 +0000 |
commit | a3c660f89a9e4a69d1c9b182c21ff0654bf07143 (patch) | |
tree | 5b5f6b28a608e0afb397a86672bbfecdaa8d3469 /cmd | |
parent | d5d5fb19253e5cf85ae82063eb544c6d6874c2fe (diff) | |
download | gitea-a3c660f89a9e4a69d1c9b182c21ff0654bf07143.tar.gz gitea-a3c660f89a9e4a69d1c9b182c21ff0654bf07143.zip |
Fix panic when cloning with wrong ssh format. (#32076) (#32118)
Backport #32076 by @lunny
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/serv.go | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/cmd/serv.go b/cmd/serv.go index 2bfd111061..f74a8fd3d0 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -143,6 +143,12 @@ func runServ(c *cli.Context) error { return nil } + defer func() { + if err := recover(); err != nil { + _ = fail(ctx, "Internal Server Error", "Panic: %v\n%s", err, log.Stack(2)) + } + }() + keys := strings.Split(c.Args().First(), "-") if len(keys) != 2 || keys[0] != "key" { return fail(ctx, "Key ID format error", "Invalid key argument: %s", c.Args().First()) @@ -189,10 +195,7 @@ func runServ(c *cli.Context) error { } verb := words[0] - repoPath := words[1] - if repoPath[0] == '/' { - repoPath = repoPath[1:] - } + repoPath := strings.TrimPrefix(words[1], "/") var lfsVerb string if verb == lfsAuthenticateVerb { |