Skip to content

Commit dfa60b1

Browse files
committed
Accept port 1 when validating published port ranges
The lower bound for a published port range was checked with a strict greater-than, so port 1 was reported as an invalid range on both the host and container sides. TCP and UDP port numbers start at 1. Port 0 remains rejected, since it means "any port" rather than a specific one. Fixes #2014
1 parent d1d7635 commit dfa60b1

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Sources/Services/ContainerAPIService/Client/Parser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,13 @@ public struct Parser {
701701
throw ContainerizationError(.invalidArgument, message: "invalid publish container port: \(containerPortText)")
702702
}
703703

704-
guard hostPortRangeStart > 1,
704+
guard hostPortRangeStart >= 1,
705705
hostPortRangeStart <= hostPortRangeEnd
706706
else {
707707
throw ContainerizationError(.invalidArgument, message: "invalid publish host port range: \(hostPortText)")
708708
}
709709

710-
guard containerPortRangeStart > 1,
710+
guard containerPortRangeStart >= 1,
711711
containerPortRangeStart <= containerPortRangeEnd
712712
else {
713713
throw ContainerizationError(.invalidArgument, message: "invalid publish container port range: \(containerPortText)")

Tests/ContainerAPIClientTests/ParserTest.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ struct ParserTest {
108108
#expect(result[0].count == 1)
109109
}
110110

111+
@Test
112+
func testPublishPortOne() throws {
113+
let result = try Parser.publishPorts(["127.0.0.1:1:1/tcp"])
114+
#expect(result.count == 1)
115+
#expect(result[0].hostPort == UInt16(1))
116+
#expect(result[0].containerPort == UInt16(1))
117+
#expect(result[0].count == 1)
118+
}
119+
111120
@Test
112121
func testPublishPortInvalidProtocol() throws {
113122
#expect {

0 commit comments

Comments
 (0)