@@ -25,6 +25,7 @@ import (
25
25
"code.gitea.io/gitea/modules/setting"
26
26
27
27
"github.com/dgrijalva/jwt-go"
28
+ "github.com/kballard/go-shellquote"
28
29
"github.com/unknwon/com"
29
30
"github.com/urfave/cli"
30
31
)
@@ -59,14 +60,6 @@ func setup(logPath string, debug bool) {
59
60
}
60
61
}
61
62
62
- func parseCmd (cmd string ) (string , string ) {
63
- ss := strings .SplitN (cmd , " " , 2 )
64
- if len (ss ) != 2 {
65
- return "" , ""
66
- }
67
- return ss [0 ], strings .Replace (ss [1 ], "'/" , "'" , 1 )
68
- }
69
-
70
63
var (
71
64
allowedCommands = map [string ]models.AccessMode {
72
65
"git-upload-pack" : models .AccessModeRead ,
@@ -126,25 +119,35 @@ func runServ(c *cli.Context) error {
126
119
return nil
127
120
}
128
121
129
- verb , args := parseCmd (cmd )
122
+ words , err := shellquote .Split (cmd )
123
+ if err != nil {
124
+ fail ("Error parsing arguments" , "Failed to parse arguments: %v" , err )
125
+ }
126
+
127
+ if len (words ) < 2 {
128
+ fail ("Too few arguments" , "Too few arguments in cmd: %s" , cmd )
129
+ }
130
+
131
+ verb := words [0 ]
132
+ repoPath := words [1 ]
133
+ if repoPath [0 ] == '/' {
134
+ repoPath = repoPath [1 :]
135
+ }
130
136
131
137
var lfsVerb string
132
138
if verb == lfsAuthenticateVerb {
133
139
if ! setting .LFS .StartServer {
134
140
fail ("Unknown git command" , "LFS authentication request over SSH denied, LFS support is disabled" )
135
141
}
136
142
137
- argsSplit := strings .Split (args , " " )
138
- if len (argsSplit ) >= 2 {
139
- args = strings .TrimSpace (argsSplit [0 ])
140
- lfsVerb = strings .TrimSpace (argsSplit [1 ])
143
+ if len (words ) > 2 {
144
+ lfsVerb = words [2 ]
141
145
}
142
146
}
143
147
144
- repoPath := strings .ToLower (strings .Trim (args , "'" ))
145
148
rr := strings .SplitN (repoPath , "/" , 2 )
146
149
if len (rr ) != 2 {
147
- fail ("Invalid repository path" , "Invalid repository path: %v" , args )
150
+ fail ("Invalid repository path" , "Invalid repository path: %v" , repoPath )
148
151
}
149
152
150
153
username := strings .ToLower (rr [0 ])
0 commit comments