From 68b7caa82819d1f9090763fc7f85c218b95bc69d Mon Sep 17 00:00:00 2001 From: Alban Crequy Date: Thu, 21 Jun 2018 18:59:24 +0200 Subject: [PATCH] mountinfo: parse empty strings in source The source of a mount in /proc/self/mountinfo can unfortunately be an empty string. Before this patch, 'mount' and 'mountpoint' fail as following: $ sudo mount -t tmpfs "" /tmp/bb $ mount mount: /proc/self/mountinfo: parse error at line 64 -- ignored $ mountpoint /tmp/bb /tmp/bb is not a mountpoint This patch fixes the parsing. Signed-off-by: Alban Crequy --- cgroups/cgroups.go | 7 ++----- cmd/runtimetest/mount/mountinfo_linux.go | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/cgroups/cgroups.go b/cgroups/cgroups.go index e108f310..5495c5c0 100644 --- a/cgroups/cgroups.go +++ b/cgroups/cgroups.go @@ -44,7 +44,7 @@ func FindCgroup() (Cgroup, error) { fields := strings.Split(text, " ") // Safe as mountinfo encodes mountpoints with spaces as \040. index := strings.Index(text, " - ") - postSeparatorFields := strings.Fields(text[index+3:]) + postSeparatorFields := strings.Split(text[index+3:], " ") numPostFields := len(postSeparatorFields) // This is an error as we can't detect if the mount is for "cgroup" @@ -53,10 +53,7 @@ func FindCgroup() (Cgroup, error) { } if postSeparatorFields[0] == "cgroup" { - // Check that the mount is properly formated. - if numPostFields < 3 { - return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text) - } + // No need to parse the rest of the postSeparatorFields cg := &CgroupV1{ MountPath: filepath.Dir(fields[4]), diff --git a/cmd/runtimetest/mount/mountinfo_linux.go b/cmd/runtimetest/mount/mountinfo_linux.go index be69fee1..44170c8b 100644 --- a/cmd/runtimetest/mount/mountinfo_linux.go +++ b/cmd/runtimetest/mount/mountinfo_linux.go @@ -64,7 +64,7 @@ func parseInfoFile(r io.Reader) ([]*Info, error) { } // Safe as mountinfo encodes mountpoints with spaces as \040. index := strings.Index(text, " - ") - postSeparatorFields := strings.Fields(text[index+3:]) + postSeparatorFields := strings.Split(text[index+3:], " ") if len(postSeparatorFields) < 3 { return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text) }