diff --git a/uinput.go b/uinput.go index 1eb1171..4195f1d 100644 --- a/uinput.go +++ b/uinput.go @@ -97,6 +97,9 @@ func validateDevicePath(path string) { } func validateUinputName(name []byte) { + if name == nil || len(name) == 0 { + panic(fmt.Sprintf("device name may not be empty")) + } if len(name) > uinputMaxNameSize { panic(fmt.Sprintf("device name %s is too long (maximum of %d characters allowed)", name, uinputMaxNameSize)) } diff --git a/uinput_test.go b/uinput_test.go index 7934d73..37789ba 100644 --- a/uinput_test.go +++ b/uinput_test.go @@ -30,3 +30,17 @@ func TestValidateDevicePathInvalidPathPanics(t *testing.T) { validateDevicePath(path) t.Fatalf("Invalid path did not yield a panic") } + +func TestValidateUinputNameEmptyNamePanics(t *testing.T) { + expected := "device name may not be empty" + defer func() { + if r := recover(); r != nil { + actual := r.(string) + if actual != expected { + t.Fatalf("Expected: %s\nActual: %s", expected, actual) + } + } + }() + validateUinputName(nil) + t.Fatalf("expected panic due to validation error, but nothing happened...") +}