From 2b89a0a0d27d6704f78f3720c1a033b9ac2b7e28 Mon Sep 17 00:00:00 2001 From: Peng Tao Date: Tue, 11 Sep 2018 15:58:03 +0800 Subject: [PATCH] uevent: fix crash on read errors The bufio package does not accept negative read count. Upon error, reset the negative count before returning the result to bufio package. Fixes: #366 Signed-off-by: Peng Tao --- pkg/uevent/uevent.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/uevent/uevent.go b/pkg/uevent/uevent.go index a0cbc79714..fc2c127469 100644 --- a/pkg/uevent/uevent.go +++ b/pkg/uevent/uevent.go @@ -56,7 +56,11 @@ func NewReaderCloser() (io.ReadCloser, error) { // Read implements reading function for uevent. func (r *ReaderCloser) Read(p []byte) (int, error) { - return unix.Read(r.fd, p) + count, err := unix.Read(r.fd, p) + if count < 0 && err != nil { + count = 0 + } + return count, err } // Close implements closing function for uevent.