From 65b313626181b0e9fa4a763cd750a2df12fb5459 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 24 Sep 2024 09:30:05 +0800 Subject: [PATCH] Fix panic when cloning with wrong ssh format. (#32076) (cherry picked from commit 3f2d8f873035b614b4cdb447d8e16f5af82cefe8) --- cmd/serv.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/serv.go b/cmd/serv.go index 0e3006b36b..db67e36fa3 100644 --- a/cmd/serv.go +++ b/cmd/serv.go @@ -147,6 +147,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()) @@ -193,10 +199,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 {