Skip to content

Commit e5bc18f

Browse files
committed
Use shellquote to unpack arguments to gitea serv
Fix #12471 Signed-off-by: Andrew Thornton <[email protected]>
1 parent e25d486 commit e5bc18f

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

cmd/serv.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"code.gitea.io/gitea/modules/setting"
2626

2727
"github.com/dgrijalva/jwt-go"
28+
"github.com/kballard/go-shellquote"
2829
"github.com/unknwon/com"
2930
"github.com/urfave/cli"
3031
)
@@ -126,25 +127,35 @@ func runServ(c *cli.Context) error {
126127
return nil
127128
}
128129

129-
verb, args := parseCmd(cmd)
130+
words, err := shellquote.Split(cmd)
131+
if err != nil {
132+
fail("Error parsing arguments", "Failed to parse arguments: %v", err)
133+
}
134+
135+
if len(words) < 2 {
136+
fail("Too few arguments", "Too few arguments in cmd: %s", cmd)
137+
}
138+
139+
verb := words[0]
140+
repoPath := words[1]
141+
if repoPath[0] == '/' {
142+
repoPath = repoPath[1:]
143+
}
130144

131145
var lfsVerb string
132146
if verb == lfsAuthenticateVerb {
133147
if !setting.LFS.StartServer {
134148
fail("Unknown git command", "LFS authentication request over SSH denied, LFS support is disabled")
135149
}
136150

137-
argsSplit := strings.Split(args, " ")
138-
if len(argsSplit) >= 2 {
139-
args = strings.TrimSpace(argsSplit[0])
140-
lfsVerb = strings.TrimSpace(argsSplit[1])
151+
if len(words) > 2 {
152+
lfsVerb = words[2]
141153
}
142154
}
143155

144-
repoPath := strings.ToLower(strings.Trim(args, "'"))
145156
rr := strings.SplitN(repoPath, "/", 2)
146157
if len(rr) != 2 {
147-
fail("Invalid repository path", "Invalid repository path: %v", args)
158+
fail("Invalid repository path", "Invalid repository path: %v", repoPath)
148159
}
149160

150161
username := strings.ToLower(rr[0])

0 commit comments

Comments
 (0)