summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-06-04 09:37:27 +0200
committerValentin Rothberg <rothberg@redhat.com>2020-06-04 09:37:27 +0200
commit6229d9d07dc16cb4b4f7b35716a59b9432bbd651 (patch)
tree9bdcc4fccf55a4165b7ce5874421edbb286f1e25
parent1f8c509fafb4ce41970c4f28ed55daec459c7520 (diff)
downloadpodman-6229d9d07dc16cb4b4f7b35716a59b9432bbd651.tar.gz
podman-6229d9d07dc16cb4b4f7b35716a59b9432bbd651.tar.bz2
podman-6229d9d07dc16cb4b4f7b35716a59b9432bbd651.zip
/images/.../json: fix port parsing
Fix a bug when parsing the `ExposedPorts` of the image that lead to panics when the field was set. The OCI image spec allows three valid formats: `tcp/port`, `udp/port` and `port` Fixes: #6490 Reported-by: @jgallucci32 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
-rw-r--r--pkg/api/handlers/types.go27
1 files changed, 18 insertions, 9 deletions
diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go
index aa3d0fe91..79aeff2f8 100644
--- a/pkg/api/handlers/types.go
+++ b/pkg/api/handlers/types.go
@@ -334,16 +334,25 @@ func ImageDataToImageInspect(ctx context.Context, l *libpodImage.Image) (*ImageI
func portsToPortSet(input map[string]struct{}) (nat.PortSet, error) {
ports := make(nat.PortSet)
for k := range input {
- npTCP, err := nat.NewPort("tcp", k)
- if err != nil {
- return nil, errors.Wrapf(err, "unable to create tcp port from %s", k)
- }
- npUDP, err := nat.NewPort("udp", k)
- if err != nil {
- return nil, errors.Wrapf(err, "unable to create udp port from %s", k)
+ proto, port := nat.SplitProtoPort(k)
+ switch proto {
+ // See the OCI image spec for details:
+ // https://github.com/opencontainers/image-spec/blob/e562b04403929d582d449ae5386ff79dd7961a11/config.md#properties
+ case "tcp", "":
+ p, err := nat.NewPort("tcp", port)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to create tcp port from %s", k)
+ }
+ ports[p] = struct{}{}
+ case "udp":
+ p, err := nat.NewPort("udp", port)
+ if err != nil {
+ return nil, errors.Wrapf(err, "unable to create tcp port from %s", k)
+ }
+ ports[p] = struct{}{}
+ default:
+ return nil, errors.Errorf("invalid port proto %q in %q", proto, k)
}
- ports[npTCP] = struct{}{}
- ports[npUDP] = struct{}{}
}
return ports, nil
}