Skip to content

Commit 65ad69b

Browse files
authored
[5.9] sandbox: UInt8 is too small to hold a TCP or UDP port (#6521)
1 parent 4eb6d74 commit 65ad69b

File tree

8 files changed

+22
-22
lines changed

8 files changed

+22
-22
lines changed

Sources/Basics/Sandbox.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import TSCBasic
1515

1616
public enum SandboxNetworkPermission: Equatable {
1717
case none
18-
case local(ports: [UInt8])
19-
case all(ports: [UInt8])
18+
case local(ports: [Int])
19+
case all(ports: [Int])
2020
case docker
2121
case unixDomainSocket
2222

@@ -28,7 +28,7 @@ public enum SandboxNetworkPermission: Equatable {
2828
}
2929
}
3030

31-
fileprivate var ports: [UInt8] {
31+
fileprivate var ports: [Int] {
3232
switch self {
3333
case .all(let ports): return ports
3434
case .local(let ports): return ports

Sources/Commands/Utilities/DescribedPackage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ struct DescribedPackage: Encodable {
188188
struct Permission: Encodable {
189189
enum NetworkScope: Encodable {
190190
case none
191-
case local(ports: [UInt8])
192-
case all(ports: [UInt8])
191+
case local(ports: [Int])
192+
case all(ports: [Int])
193193
case docker
194194
case unixDomainSocket
195195

Sources/PackageDescription/PackageDescriptionSerialization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ enum Serialization {
184184

185185
enum PluginNetworkPermissionScope: Codable {
186186
case none
187-
case local(ports: [UInt8])
188-
case all(ports: [UInt8])
187+
case local(ports: [Int])
188+
case all(ports: [Int])
189189
case docker
190190
case unixDomainSocket
191191
}

Sources/PackageDescription/Target.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,21 +1492,21 @@ public enum PluginNetworkPermissionScope {
14921492
/// Do not allow network access.
14931493
case none
14941494
/// Allow local network connections; can be limited to a list of allowed ports.
1495-
case local(ports: [UInt8] = [])
1495+
case local(ports: [Int] = [])
14961496
/// Allow local and outgoing network connections; can be limited to a list of allowed ports.
1497-
case all(ports: [UInt8] = [])
1497+
case all(ports: [Int] = [])
14981498
/// Allow connections to Docker through UNIX domain sockets.
14991499
case docker
15001500
/// Allow connections to any UNIX domain socket.
15011501
case unixDomainSocket
15021502

15031503
/// Allow local and outgoing network connections, limited to a range of allowed ports.
1504-
public static func all(ports: Range<UInt8>) -> PluginNetworkPermissionScope {
1504+
public static func all(ports: Range<Int>) -> PluginNetworkPermissionScope {
15051505
return .all(ports: Array(ports))
15061506
}
15071507

15081508
/// Allow local network connections, limited to a range of allowed ports.
1509-
public static func local(ports: Range<UInt8>) -> PluginNetworkPermissionScope {
1509+
public static func local(ports: Range<Int>) -> PluginNetworkPermissionScope {
15101510
return .local(ports: Array(ports))
15111511
}
15121512
}

Sources/PackageModel/Manifest/TargetDescription.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ public struct TargetDescription: Equatable, Encodable, Sendable {
124124

125125
public enum PluginNetworkPermissionScope: Equatable, Codable, Sendable {
126126
case none
127-
case local(ports: [UInt8])
128-
case all(ports: [UInt8])
127+
case local(ports: [Int])
128+
case all(ports: [Int])
129129
case docker
130130
case unixDomainSocket
131131

132-
public init?(_ scopeString: String, ports: [UInt8]) {
132+
public init?(_ scopeString: String, ports: [Int]) {
133133
switch scopeString {
134134
case "none": self = .none
135135
case "local": self = .local(ports: ports)

Sources/PackageModel/Target.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -848,8 +848,8 @@ public enum PluginCommandIntent: Hashable, Codable {
848848

849849
public enum PluginNetworkPermissionScope: Hashable, Codable {
850850
case none
851-
case local(ports: [UInt8])
852-
case all(ports: [UInt8])
851+
case local(ports: [Int])
852+
case all(ports: [Int])
853853
case docker
854854
case unixDomainSocket
855855

@@ -873,7 +873,7 @@ public enum PluginNetworkPermissionScope: Hashable, Codable {
873873
}
874874
}
875875

876-
public var ports: [UInt8] {
876+
public var ports: [Int] {
877877
switch self {
878878
case .all(let ports): return ports
879879
case .local(let ports): return ports

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,8 +1923,8 @@ final class PackageToolTests: CommandsTestCase {
19231923
reason: "internet good",
19241924
remedy: ["--allow-network-connections", "all"])
19251925
try testCommandPluginNetworkingPermissions(
1926-
permissionsManifestFragment: "[.allowNetworkConnections(scope: .all(ports: [23, 42]), reason: \"internet good\")]",
1927-
permissionError: "all network connections on ports: 23, 42",
1926+
permissionsManifestFragment: "[.allowNetworkConnections(scope: .all(ports: [23, 42, 443, 8080]), reason: \"internet good\")]",
1927+
permissionError: "all network connections on ports: 23, 42, 443, 8080",
19281928
reason: "internet good",
19291929
remedy: ["--allow-network-connections", "all"])
19301930
try testCommandPluginNetworkingPermissions(
@@ -1939,8 +1939,8 @@ final class PackageToolTests: CommandsTestCase {
19391939
reason: "localhost good",
19401940
remedy: ["--allow-network-connections", "local"])
19411941
try testCommandPluginNetworkingPermissions(
1942-
permissionsManifestFragment: "[.allowNetworkConnections(scope: .local(ports: [23, 42]), reason: \"localhost good\")]",
1943-
permissionError: "local network connections on ports: 23, 42",
1942+
permissionsManifestFragment: "[.allowNetworkConnections(scope: .local(ports: [23, 42, 443, 8080]), reason: \"localhost good\")]",
1943+
permissionError: "local network connections on ports: 23, 42, 443, 8080",
19441944
reason: "localhost good",
19451945
remedy: ["--allow-network-connections", "local"])
19461946
try testCommandPluginNetworkingPermissions(

Tests/WorkspaceTests/ManifestSourceGenerationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class ManifestSourceGenerationTests: XCTestCase {
587587
toolsVersion: .v5_9,
588588
dependencies: [],
589589
targets: [
590-
try TargetDescription(name: "MyPlugin", type: .plugin, pluginCapability: .command(intent: .custom(verb: "foo", description: "bar"), permissions: [.allowNetworkConnections(scope: .all(ports: [23, 42]), reason: "internet good")]))
590+
try TargetDescription(name: "MyPlugin", type: .plugin, pluginCapability: .command(intent: .custom(verb: "foo", description: "bar"), permissions: [.allowNetworkConnections(scope: .all(ports: [23, 42, 443, 8080]), reason: "internet good")]))
591591
])
592592
let contents = try manifest.generateManifestFileContents(packageDirectory: manifest.path.parentDirectory)
593593
try testManifestWritingRoundTrip(manifestContents: contents, toolsVersion: .v5_9)

0 commit comments

Comments
 (0)