From 1dfe568725a8e3d05274afb235ecd7cc32e7474d Mon Sep 17 00:00:00 2001 From: Benjamin Dahlmanns Date: Tue, 13 Nov 2018 21:18:41 +0100 Subject: [PATCH] Add test case for empty device name --- uinput.go | 3 +++ uinput_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+) 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...") +}