代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/docker 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 405d10b7df5fa329a7070cb842a8d5e4e46861d6 Mon Sep 17 00:00:00 2001
From: lixiang172 <lixiang172@huawei.com>
Date: Mon, 18 Feb 2019 22:13:53 +0800
Subject: [PATCH 103/111] docker: fix parsing name with /
reason: fix parsing name with /
Do the error check when using --link option,
if the alias name and container name is the same, return error
Change-Id: I64c39915d34d79ee8abbba2ebe0e66ad3ad08551
Signed-off-by: yangshukui <yangshukui@huawei.com>
Signed-off-by: lixiang172 <lixiang172@huawei.com>
---
components/engine/daemon/daemon.go | 13 +++++++++++++
.../engine/integration-cli/docker_cli_links_test.go | 8 ++++++++
2 files changed, 21 insertions(+)
diff --git a/components/engine/daemon/daemon.go b/components/engine/daemon/daemon.go
index f5d22bb18b..e26494ed68 100644
--- a/components/engine/daemon/daemon.go
+++ b/components/engine/daemon/daemon.go
@@ -657,8 +657,21 @@ func (daemon *Daemon) parents(c *container.Container) map[string]*container.Cont
return daemon.linkIndex.parents(c)
}
+func validateAlias(alias string, c *container.Container) error {
+ if !validContainerNamePattern.MatchString(alias) {
+ return fmt.Errorf("Invalid alias name (%s), only %s are allowed", alias, validContainerNameChars)
+ }
+ if alias == c.Config.Hostname {
+ return fmt.Errorf("Invalid alias name (%s), alias is the same to current container's hostname", alias)
+ }
+ return nil
+}
+
func (daemon *Daemon) registerLink(parent, child *container.Container, alias string) error {
fullName := path.Join(parent.Name, alias)
+ if err := validateAlias(alias, parent); err != nil {
+ return err
+ }
if err := daemon.containersReplica.ReserveName(fullName, child.ID); err != nil {
if err == container.ErrNameReserved {
logrus.Warnf("error registering link for %s, to %s, as alias %s, ignoring: %v", parent.ID, child.ID, alias, err)
diff --git a/components/engine/integration-cli/docker_cli_links_test.go b/components/engine/integration-cli/docker_cli_links_test.go
index 17b25d7994..9efa1cfbf6 100644
--- a/components/engine/integration-cli/docker_cli_links_test.go
+++ b/components/engine/integration-cli/docker_cli_links_test.go
@@ -237,3 +237,11 @@ func (s *DockerSuite) TestLinksMultipleWithSameName(c *check.C) {
dockerCmd(c, "run", "-d", "--name=upstream-b", "busybox", "top")
dockerCmd(c, "run", "--link", "upstream-a:upstream", "--link", "upstream-b:upstream", "busybox", "sh", "-c", "ping -c 1 upstream")
}
+func (s *DockerSuite) TestLinksAliasCheck(c *check.C) {
+ testRequires(c, DaemonIsLinux, NotUserNamespace)
+ dockerCmd(c, "run", "-d", "--name=linkalias", "busybox", "top")
+ out, _, _ := dockerCmdWithError("run", "-d", "--link=linkalias:hello/sep", "busybox", "top")
+ c.Assert(out, checker.Contains, "Invalid alias name")
+ out, _, _ = dockerCmdWithError("run", "-d", "--hostname=linkhostname", "--link=linkalias:linkhostname", "busybox", "top")
+ c.Assert(out, checker.Contains, "alias is the same to current container's hostname")
+}
--
2.17.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。