Repository navigation
Validate hostConfig on daemon. Check for invalid port specifications - #14231
Conversation
|
@ankushagarwal I think real problem is panic in https://github.com/docker/docker/blob/master/nat/nat.go#L60 wdyt? |
|
Yup, noticed that. That function (https://github.com/docker/docker/blob/master/nat/nat.go#L57) is very badly written. It tries to convert a string to int and panics when it can't. Instead of panic, it should be returning an error. I will try to open another issue to fix that. A lot of refactoring needs to be done to fix that. In this fix, I am making sure that while parsing the HostConfig, the ports are in proper format and doing an early exit. |
|
The problem is that panic tho. Wouldn't be better to add that kind of validation in https://github.com/ankushagarwal/docker/blob/checkValidPort/daemon/container_linux.go#L666 that is where this check is missing (I suppose, I'm actually on my phone, since there we are checking mac as well)? And then it won't be a mess to refactor |
|
Agreed. Will refactor. |
|
On second thoughts, I think we should catch invalid Ports (and other invalid objects) as soon as we |
|
@ankushagarwal it would be awesome to have an integration test to make sure we don't break this again. Otherwise, the patch LGTM. |
There was a problem hiding this comment.
I think it should be:
_, err := ParsePort(portStr)
return err
Also, error is keyword for type in golang, better not use it for your variables.
|
Updated |
|
you can write integration tests that talk with the api directly, like the ones in this file: |
|
I think tests are failing because |
|
Added the nil check. Hopefully tests pass now. Will add the integration test now. |
|
Added an integration test. Can't figure out why experimental is failing. |
There was a problem hiding this comment.
Sorry, can we change this to only supply required fields?
This would be config.Image and config.HostCofig.PortBindings for this test.
Fixes #14230 Signed-off-by: Ankush Agarwal <[email protected]>
|
thanks @ankushagarwal. LGTM |
|
LGTM |
Validate hostConfig on daemon. Check for invalid port specifications
|
Cherry picked into the release branch. |
Currently only checks for proper port specification as port
is specified as a string and any arbitrary string can be passed as port
Fixes #14230