From a9daf5053260f58195a07b34b9a59bef671faf45 Mon Sep 17 00:00:00 2001 From: Liu Hua Date: Thu, 28 Jan 2016 22:17:28 +0800 Subject: [PATCH] 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 Upstream-commit: 755df347fbaf6a02e6bdc2d5b7339aade2dbade0 Component: engine --- components/engine/api/client/login.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/engine/api/client/login.go b/components/engine/api/client/login.go index 21fde012d9..fe995e4b04 100644 --- a/components/engine/api/client/login.go +++ b/components/engine/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") } }