Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/Containerization/LinuxContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import struct ContainerizationOS.Terminal
/// `LinuxContainer` is an easy to use type for launching and managing the
/// full lifecycle of a Linux container ran inside of a virtual machine.
public final class LinuxContainer: Container, Sendable {
static let maxIDLength = 64

/// The identifier of the container.
public let id: String

Expand Down Expand Up @@ -332,6 +334,12 @@ public final class LinuxContainer: Container, Sendable {
configuration: LinuxContainer.Configuration,
logger: Logger? = nil
) throws {
guard id.count <= Self.maxIDLength else {
throw ContainerizationError(
.invalidArgument,
message: "container id length \(id.count) exceeds maximum of \(Self.maxIDLength) characters"
)
}
if let writableLayer {
guard writableLayer.isBlock else {
throw ContainerizationError(
Expand Down
14 changes: 14 additions & 0 deletions Sources/Containerization/LinuxPod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import struct ContainerizationOS.Terminal
/// virtual machine. Each container has its own rootfs and process, but
/// shares the VM's resources (CPU, memory, network).
public final class LinuxPod: Sendable {
static let maxIDLength = 64

/// The identifier of the pod.
public let id: String

Expand Down Expand Up @@ -223,6 +225,12 @@ public final class LinuxPod: Sendable {
logger: Logger? = nil,
configuration: (inout Configuration) throws -> Void
) throws {
guard id.count <= Self.maxIDLength else {
throw ContainerizationError(
.invalidArgument,
message: "pod id length \(id.count) exceeds maximum of \(Self.maxIDLength) characters"
)
}
self.id = id
self.vmm = vmm
self.hostVsockPorts = Atomic<UInt32>(0x1000_0000)
Expand Down Expand Up @@ -328,6 +336,12 @@ extension LinuxPod {
rootfs: Mount,
configuration: @Sendable @escaping (inout ContainerConfiguration) throws -> Void
) async throws {
guard id.count <= Self.maxIDLength else {
throw ContainerizationError(
.invalidArgument,
message: "container id length \(id.count) exceeds maximum of \(Self.maxIDLength) characters"
)
}
try await self.state.withLock { state in
guard case .initialized = state.phase else {
throw ContainerizationError(
Expand Down
Loading