mirror of
https://github.com/containers/podman.git
synced 2025-10-19 12:12:36 +08:00
Correct port range logic for port generation
The existing logic (Range > 0) always triggered, because range is guaranteed to be at least 1 (a single port has a range of 1, a two port range (e.g. 80-81) has a range of 2, and so on). As such this could cause ports that had a host port assigned to them by the user to randomly assign one instead. Fixes #8650 Fixes #8651 Signed-off-by: Matthew Heon <mheon@redhat.com>
This commit is contained in:
@ -107,7 +107,11 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
|
||||
var index uint16
|
||||
for index = 0; index < len; index++ {
|
||||
cPort := containerPort + index
|
||||
hPort := hostPort + index
|
||||
hPort := hostPort
|
||||
// Only increment host port if it's not 0.
|
||||
if hostPort != 0 {
|
||||
hPort += index
|
||||
}
|
||||
|
||||
if cPort == 0 {
|
||||
return nil, nil, nil, errors.Errorf("container port cannot be 0")
|
||||
@ -162,8 +166,8 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
|
||||
tempMappings,
|
||||
tempMapping{
|
||||
mapping: cniPort,
|
||||
startOfRange: port.Range > 0 && index == 0,
|
||||
isInRange: port.Range > 0,
|
||||
startOfRange: port.Range > 1 && index == 0,
|
||||
isInRange: port.Range > 1,
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -183,7 +187,7 @@ func parsePortMapping(portMappings []specgen.PortMapping) ([]ocicni.PortMapping,
|
||||
for _, tmp := range tempMappings {
|
||||
p := tmp.mapping
|
||||
|
||||
if p.HostPort != 0 && !tmp.isInRange {
|
||||
if p.HostPort != 0 {
|
||||
remadeMappings = append(remadeMappings, p)
|
||||
continue
|
||||
}
|
||||
|
Reference in New Issue
Block a user