@@ -25,7 +25,7 @@ func normalizeWindowsPath(path string) string {
2525 return normalizedPath
2626}
2727
28- func normalizeMappingPath (path string ) string {
28+ func getRootMappingPath (path string ) ( string , error ) {
2929 items := strings .Split (path , "\\ " )
3030 parts := []string {}
3131 for _ , s := range items {
@@ -36,7 +36,13 @@ func normalizeMappingPath(path string) string {
3636 }
3737 }
3838 }
39- return strings .ToLower ("\\ \\ " + parts [0 ] + "\\ " + parts [1 ])
39+ if len (parts ) != 2 {
40+ klog .Errorf ("remote path (%s) is invalid" , path )
41+ return nil , fmt .Errorf ("remote path (%s) is invalid" , path )
42+ }
43+ // parts[0] is a smb host name
44+ // parts[1] is a smb share name
45+ return strings .ToLower ("\\ \\ " + parts [0 ] + "\\ " + parts [1 ]), nil
4046}
4147
4248func NewServer (hostAPI smb.API , fsServer * fsserver.Server ) (* Server , error ) {
@@ -57,7 +63,9 @@ func (s *Server) NewSmbGlobalMapping(context context.Context, request *internal.
5763 return response , fmt .Errorf ("remote path is empty" )
5864 }
5965
60- mappingPath := normalizeMappingPath (remotePath )
66+ if mappingPath , err := getRootMappingPath (remotePath ); err != nil {
67+ return response , err ;
68+ }
6169
6270 isMapped , err := s .hostAPI .IsSmbMapped (mappingPath )
6371 if err != nil {
@@ -122,7 +130,10 @@ func (s *Server) RemoveSmbGlobalMapping(context context.Context, request *intern
122130 return response , fmt .Errorf ("remote path is empty" )
123131 }
124132
125- mappingPath := normalizeMappingPath (remotePath )
133+ if mappingPath , err := getRootMappingPath (remotePath ); err != nil {
134+ return response , err ;
135+ }
136+
126137 err := s .hostAPI .RemoveSmbGlobalMapping (mappingPath )
127138 if err != nil {
128139 klog .Errorf ("failed RemoveSmbGlobalMapping %v" , err )
0 commit comments