{"record":{"id":"d524ab47ff9e144e","repo":"docker/cli","slug":"invalid-device-specification-s","errorCode":null,"errorMessage":"invalid device specification: %s","messagePattern":"invalid device specification: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":1028,"sourceCode":"\tvar src, dst string\n\tpermissions := \"rwm\"\n\t// We expect 3 parts at maximum; limit to 4 parts to detect invalid options.\n\tarr := strings.SplitN(device, \":\", 4)\n\tswitch len(arr) {\n\tcase 3:\n\t\tpermissions = arr[2]\n\t\tfallthrough\n\tcase 2:\n\t\tif validDeviceMode(arr[1]) {\n\t\t\tpermissions = arr[1]\n\t\t} else {\n\t\t\tdst = arr[1]\n\t\t}\n\t\tfallthrough\n\tcase 1:\n\t\tsrc = arr[0]\n\tdefault:\n\t\treturn container.DeviceMapping{}, fmt.Errorf(\"invalid device specification: %s\", device)\n\t}\n\n\tif dst == \"\" {\n\t\tdst = src\n\t}\n\n\treturn container.DeviceMapping{\n\t\tPathOnHost:        src,\n\t\tPathInContainer:   dst,\n\t\tCgroupPermissions: permissions,\n\t}, nil\n}\n\n// validateDeviceCgroupRule validates a device cgroup rule string format\n// It will make sure 'val' is in the form:\n//\n//\t'type major:minor mode'\nfunc validateDeviceCgroupRule(val string) (string, error) {","sourceCodeStart":1010,"sourceCodeEnd":1046,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/opts.go#L1010-L1046","documentation":"Thrown by parseLinuxDevice when the device string splits into 4 or more colon-separated parts (strings.SplitN with limit 4 returns len 4), exceeding the maximum of src[:dst[:mode]]. This means too many colons were supplied.","triggerScenarios":"Calling `docker run --device a:b:c:d` (three colons yields 4 parts). The expected formats are /dev/src, /dev/src:/dev/dst, or /dev/src:/dev/dst:rwm.","commonSituations":"Typing an extra colon; using a Windows-style path with a drive letter inside a Linux device spec (e.g. C:\\... converted); copy-pasting a path containing colons; misunderstanding the three-field limit.","solutions":["Use at most two colons: --device /dev/sda1:/dev/sda1:rwm","Remove extra segments; a device spec has at most host[:container[:mode]]","Quote paths containing colons appropriately or avoid them"],"exampleFix":"# before\ndocker run --device /dev/loop0:/dev/loop0:rwm:extra ...\n# after\ndocker run --device /dev/loop0:/dev/loop0:rwm ...","handlingStrategy":"validation","validationCode":"// Reject device specs with too many colon segments.\nfunc validDeviceSpec(spec string) error {\n    if strings.Count(spec, \":\") > 2 {\n        return fmt.Errorf(\"device spec %q has too many segments\", spec)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Construct device specs from typed fields rather than raw string concatenation"],"tags":["docker","device","cli-validation","parse"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}