From ef09072c4d02f4c78b48250cee14681b678a3b5c Mon Sep 17 00:00:00 2001 From: guojunding Date: Thu, 18 Jul 2024 15:41:24 +0800 Subject: [PATCH] Fix NPE due to null value returned by ep.Iface() --- ...e-to-null-value-returned-by-ep.Iface.patch | 71 +++++++++++++++++++ libnetwork.spec | 9 ++- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 backport-Fix-NPE-due-to-null-value-returned-by-ep.Iface.patch diff --git a/backport-Fix-NPE-due-to-null-value-returned-by-ep.Iface.patch b/backport-Fix-NPE-due-to-null-value-returned-by-ep.Iface.patch new file mode 100644 index 0000000..2628f61 --- /dev/null +++ b/backport-Fix-NPE-due-to-null-value-returned-by-ep.Iface.patch @@ -0,0 +1,71 @@ +From b09f24d11651e555c529028cadde2d365d6e2436 Mon Sep 17 00:00:00 2001 +From: Arko Dasgupta +Date: Thu, 2 Apr 2020 21:21:47 -0700 +Subject: [PATCH] Fix NPE due to null value returned by ep.Iface() + +This PR carryforwards https://github.com/moby/libnetwork/pull/2239 +and incorporates the suggestions in comments to fix the NPE and +potential NPEs due to a null value returned by ep.Iface() + +Signed-off-by: Arko Dasgupta +(cherry picked from commit c55657fd53dd26c8f7a828aed9aaa63441f3c6f4) +Signed-off-by: Sebastiaan van Stijn +--- + agent.go | 4 ++-- + controller.go | 4 ++++ + network.go | 2 +- + 3 files changed, 7 insertions(+), 3 deletions(-) + +diff --git libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9/agent.go libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9-b/agent.go +index c90fa81..550f310 100644 +--- libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9/agent.go ++++ libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9-b/agent.go +@@ -583,7 +583,7 @@ func (ep *endpoint) deleteDriverInfoFromCluster() error { + } + + func (ep *endpoint) addServiceInfoToCluster(sb *sandbox) error { +- if ep.isAnonymous() && len(ep.myAliases) == 0 || ep.Iface().Address() == nil { ++ if ep.isAnonymous() && len(ep.myAliases) == 0 || ep.Iface() == nil || ep.Iface().Address() == nil { + return nil + } + +@@ -706,7 +706,7 @@ func (ep *endpoint) deleteServiceInfoFromCluster(sb *sandbox, fullRemove bool, m + } + } + +- if ep.Iface().Address() != nil { ++ if ep.Iface() != nil && ep.Iface().Address() != nil { + if ep.svcID != "" { + // This is a task part of a service + var ingressPorts []*PortConfig +diff --git libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9/controller.go libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9-b/controller.go +index f3b6b02..99f4074 100644 +--- libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9/controller.go ++++ libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9-b/controller.go +@@ -952,6 +952,10 @@ func (c *controller) reservePools() { + continue + } + for _, ep := range epl { ++ if ep.Iface() == nil { ++ logrus.Warnf("endpoint interface is empty for %q (%s)", ep.Name(), ep.ID()) ++ continue ++ } + if err := ep.assignAddress(ipam, true, ep.Iface().AddressIPv6() != nil); err != nil { + logrus.Warnf("Failed to reserve current address for endpoint %q (%s) on network %q (%s)", + ep.Name(), ep.ID(), n.Name(), n.ID()) +diff --git libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9/network.go libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9-b/network.go +index 5ca660c..f69b27f 100644 +--- libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9/network.go ++++ libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9-b/network.go +@@ -1314,7 +1314,7 @@ func (n *network) EndpointByID(id string) (Endpoint, error) { + func (n *network) updateSvcRecord(ep *endpoint, localEps []*endpoint, isAdd bool) { + var ipv6 net.IP + epName := ep.Name() +- if iface := ep.Iface(); iface.Address() != nil { ++ if iface := ep.Iface(); iface != nil && iface.Address() != nil { + myAliases := ep.MyAliases() + if iface.AddressIPv6() != nil { + ipv6 = iface.AddressIPv6().IP +-- +2.9.3.windows.1 + diff --git a/libnetwork.spec b/libnetwork.spec index 5a061cc..2e1949f 100644 --- a/libnetwork.spec +++ b/libnetwork.spec @@ -1,11 +1,14 @@ %define debug_package %{nil} Name: libnetwork Version: 0.8.0.dev.2 -Release: 104 +Release: 105 Summary: Proxy used for docker port mapping License: Apache License 2.0 URL: https://github.com/docker/libnetwork Source: libnetwork-d00ceed.tar.gz + +Patch1: backport-Fix-NPE-due-to-null-value-returned-by-ep.Iface.patch + BuildRequires: golang >= 1.8.3 BuildRequires: make Provides: docker-proxy @@ -15,6 +18,7 @@ Obsoletes: docker-proxy %prep %setup -c -n libnetwork +%patch1 -p0 %build cd libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9 @@ -48,6 +52,9 @@ install -p -m 755 libnetwork-d00ceed44cc447c77f25cdf5d59e83163bdcb4c9/docker-pro %{_bindir}/docker-proxy %changelog +* Thu Jul 18 2024 guojunding - 0.8.0.dev.2-105 +- Fix NPE due to null value returned by ep.Iface() + * Mon Aug 14 2023 suwei - 0.8.0.dev.2-104 - Type:enhencement - Id:NA -- Gitee