Explorar el Código

forbid login of a null-string username

With this patch, the client blocks this type login, no sending
useless messages to daemon and registry. This saves lots of time.

Signed-off-by: Liu Hua <sdu.liu@huawei.com>
Liu Hua hace 9 años
padre
commit
755df347fb
Se han modificado 1 ficheros con 7 adiciones y 2 borrados
  1. 7 2
      api/client/login.go

+ 7 - 2
api/client/login.go

@@ -81,8 +81,9 @@ func (cli *DockerCli) configureAuth(flUser, flPassword, flEmail, serverAddress s
 	if !ok {
 		authconfig = types.AuthConfig{}
 	}
+	authconfig.Username = strings.TrimSpace(authconfig.Username)
 
-	if flUser == "" {
+	if flUser = strings.TrimSpace(flUser); flUser == "" {
 		cli.promptWithDefault("Username", authconfig.Username)
 		flUser = readInput(cli.in, cli.out)
 		flUser = strings.TrimSpace(flUser)
@@ -91,6 +92,10 @@ func (cli *DockerCli) configureAuth(flUser, flPassword, flEmail, serverAddress s
 		}
 	}
 
+	if flUser == "" {
+		return authconfig, fmt.Errorf("Error: Non-null Username Required")
+	}
+
 	if flPassword == "" {
 		oldState, err := term.SaveState(cli.inFd)
 		if err != nil {
@@ -104,7 +109,7 @@ func (cli *DockerCli) configureAuth(flUser, flPassword, flEmail, serverAddress s
 
 		term.RestoreTerminal(cli.inFd, oldState)
 		if flPassword == "" {
-			return authconfig, fmt.Errorf("Error : Password Required")
+			return authconfig, fmt.Errorf("Error: Password Required")
 		}
 	}