]> source.dussan.org Git - gitea.git/commitdiff
Fix panic when cloning with wrong ssh format. (#32076)
authorLunny Xiao <xiaolunwen@gmail.com>
Tue, 24 Sep 2024 01:30:05 +0000 (09:30 +0800)
committerGitHub <noreply@github.com>
Tue, 24 Sep 2024 01:30:05 +0000 (01:30 +0000)
cmd/serv.go

index 2bfd1110617e5be9f7eaca26ba79cdaca7845c10..f74a8fd3d071c01ccc867245dbd36506973cbe77 100644 (file)
@@ -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 {