From 5b658a034809c0b66998cb7ed222d5535d8b82bc Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 11 Mar 2020 19:09:30 -0700 Subject: [PATCH 1/2] daemon.overlaySupportsSelinux: simplify check 1. Sscanf is very slow, and we don't use the first two fields -- get rid of it. 2. Since the field we search for is at the end of line and prepended by a space, we can just use strings.HaveSuffix. 3. Error checking for bufio.Scanner should be done after the Scan() loop, not inside it. Fixes: 885b29df096db1d Signed-off-by: Kir Kolyshkin --- daemon/daemon_unix.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 0cd82b4ae9..ac552c8f08 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -838,25 +838,14 @@ func overlaySupportsSelinux() (bool, error) { } defer f.Close() - var symAddr, symType, symName, text string - s := bufio.NewScanner(f) for s.Scan() { - if err := s.Err(); err != nil { - return false, err - } - - text = s.Text() - if _, err := fmt.Sscanf(text, "%s %s %s", &symAddr, &symType, &symName); err != nil { - return false, fmt.Errorf("Scanning '%s' failed: %s", text, err) - } - - // Check for presence of symbol security_inode_copy_up. - if symName == "security_inode_copy_up" { + if strings.HasSuffix(s.Text(), " security_inode_copy_up") { return true, nil } } - return false, nil + + return false, s.Err() } // configureKernelSecuritySupport configures and validates security support for the kernel From 745ed9686b7bf09399aa013236b8112e63722dfe Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 11 Mar 2020 19:16:29 -0700 Subject: [PATCH 2/2] pkg/idtools: fix use of bufio.Scanner.Err The Err() method should be called after the Scan() loop, not inside it. Fixes: 9a3ab0358ec Signed-off-by: Kir Kolyshkin --- pkg/idtools/idtools.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/idtools/idtools.go b/pkg/idtools/idtools.go index b3af7a4226..db1fd1a9d1 100644 --- a/pkg/idtools/idtools.go +++ b/pkg/idtools/idtools.go @@ -236,10 +236,6 @@ func parseSubidFile(path, username string) (ranges, error) { s := bufio.NewScanner(subidFile) for s.Scan() { - if err := s.Err(); err != nil { - return rangeList, err - } - text := strings.TrimSpace(s.Text()) if text == "" || strings.HasPrefix(text, "#") { continue @@ -260,5 +256,6 @@ func parseSubidFile(path, username string) (ranges, error) { rangeList = append(rangeList, subIDRange{startid, length}) } } - return rangeList, nil + + return rangeList, s.Err() }