mirror of
https://github.com/containers/podman.git
synced 2025-06-28 06:18:57 +08:00
pkg/specgen: Don't crash for device spec with...
...empty destination path This fixes a server-side crash for command lines like: # podman run -ti --rm --device /dev/mem::rw alpine sh Fixes #19335. Signed-off-by: Doug Rabson <dfr@rabson.org>
This commit is contained in:
@ -26,3 +26,25 @@ func TestShouldMask(t *testing.T) {
|
||||
assert.Equal(t, val, test.shouldMask)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDevice(t *testing.T) {
|
||||
tests := []struct {
|
||||
device string
|
||||
src string
|
||||
dst string
|
||||
perm string
|
||||
}{
|
||||
{"/dev/foo", "/dev/foo", "/dev/foo", "rwm"},
|
||||
{"/dev/foo:/dev/bar", "/dev/foo", "/dev/bar", "rwm"},
|
||||
{"/dev/foo:/dev/bar:rw", "/dev/foo", "/dev/bar", "rw"},
|
||||
{"/dev/foo:rw", "/dev/foo", "/dev/foo", "rw"},
|
||||
{"/dev/foo::rw", "/dev/foo", "/dev/foo", "rw"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
src, dst, perm, err := ParseDevice(test.device)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, src, test.src)
|
||||
assert.Equal(t, dst, test.dst)
|
||||
assert.Equal(t, perm, test.perm)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user