-
Notifications
You must be signed in to change notification settings - Fork 886
Prevent NPE in addServiceInfoToCluster() #2239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
`ep.Iface()` can return `nil`, in which case `Address()` would result in a NPE. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
|
|
||
| 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use some input here; I started with this, but noticed there's quite some places where a "fluent" interface is used (foo.Iface().SomeFunction()), so having to check in all places is likely problematic.
| } | ||
|
|
||
| return nil | ||
| return &endpointInterface{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this would work to prevent the situation, but I see there's many other places where nil can be returned, which won't really work with a fluent interface 😓, so likely all those occurrences need to be addressed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so I grepped the code specifically for \.Iface\(\) and came away with the following locations where it is used. Most of the fluid uses are protected by tests and so don't need further protection. Here are the locations I think need further protection:
- agent.go L586 -- already mentioned above
- agent.go L709 -- could add a protection similar to L586 at the start of the function: L668
- controller.go L955 -- Probably needs an
if ep.Iface() == nil { continue }right before - network.go L1317 -- Should probably become
iface := ep.Iface(); if iface != nil && iface.Address() != nil { ...
So we should be covered without returning the&endpointInterface{}if we add three more tests.
Just as a side comment:
- service_windows.go L41 -- should be protected by epInfo.LoadBalancer() test
- service_linux.go (all) -- all fluid references are protected by a call to findLBEndpointSandbox() which only returns the endpoint if
epi.LoadBalancer()is true. (as per Windows above) - maybe there's some kind of race in those files where somone tries to add a binding while the sandbox is still coming up? But I'm not sure. If so, then a test in findLBEndpointSandbox() would be in order for
service_linux.go. - there are a few test files that are unprotected -- I'm not worried about those.
I'm not really sure why we can have endpoints without interfaces -- I thought these were a 1-to-1 mapping conceptually. But given comments in service_linux.go that indicate that this is deliberate, I'm disinclined to return a pointer to an empty structure. OTOH, I don't see anywhere in the code that is positively acting on Iface() returning nil. So, maybe it is OK after all w/ a small change to L36 of service_linux.go. Others w/ more history, please chime in.
|
ping @fcrisciani @ctelfer |
|
I see blow files are having similar implementation and invokes "ep.Iface().Address()" without checking if Iface returns null or not. @fcrisciani WDYT? |
|
Just fiy, this is still happening with docker 18.09 |
|
@selansen is this still needed ? |
|
@arkodg I just ran into this same bug, so it's likely still needed docker info: Panic trace: |
This PR carryforwards moby#2239 and incorporates the suggestions in comments to fix the NPE and potential NPEs due to null value returned by ep.Iface() Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
This PR carryforwards moby#2239 and incorporates the suggestions in comments to fix the NPE and potential NPEs due to null value returned by ep.Iface() Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
This PR carryforwards moby#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 <arko.dasgupta@docker.com>
full diff: moby/libnetwork@ef149a9...1a17fb3 - moby/libnetwork#2538 produce an error with invalid address pool - addresses moby#40388 dockerd ignores the --default-address-pool option - moby/libnetwork#2471 DOCKER-USER chain not created when IPTableEnable=false - moby/libnetwork#2544 Fix NPE due to null value returned by ep.Iface() - carries moby/libnetwork#2239 Prevent NPE in addServiceInfoToCluster() - addresses moby#37506 Error initializing docker.server while starting daemon by systemd Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
full diff: moby/libnetwork@ef149a9...1a17fb3 - moby/libnetwork#2538 produce an error with invalid address pool - addresses moby/moby#40388 dockerd ignores the --default-address-pool option - moby/libnetwork#2471 DOCKER-USER chain not created when IPTableEnable=false - moby/libnetwork#2544 Fix NPE due to null value returned by ep.Iface() - carries moby/libnetwork#2239 Prevent NPE in addServiceInfoToCluster() - addresses moby/moby#37506 Error initializing docker.server while starting daemon by systemd Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: c3808634e7a44fc5b4fb8caacd9d079f7e0a0fee Component: engine
This PR carryforwards moby/libnetwork#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 <arko.dasgupta@docker.com>
ep.Iface()can returnnil, in which caseAddress()would result in a NPE.relates to moby/moby#37506