Skip to content

Commit d2fbafa

Browse files
authored
Merge pull request #652 from kinvolk/alban/mount-empty-source
mountinfo: parse empty strings in source
2 parents b06b745 + 68b7caa commit d2fbafa

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

cgroups/cgroups.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func FindCgroup() (Cgroup, error) {
4444
fields := strings.Split(text, " ")
4545
// Safe as mountinfo encodes mountpoints with spaces as \040.
4646
index := strings.Index(text, " - ")
47-
postSeparatorFields := strings.Fields(text[index+3:])
47+
postSeparatorFields := strings.Split(text[index+3:], " ")
4848
numPostFields := len(postSeparatorFields)
4949

5050
// This is an error as we can't detect if the mount is for "cgroup"
@@ -53,10 +53,7 @@ func FindCgroup() (Cgroup, error) {
5353
}
5454

5555
if postSeparatorFields[0] == "cgroup" {
56-
// Check that the mount is properly formated.
57-
if numPostFields < 3 {
58-
return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text)
59-
}
56+
// No need to parse the rest of the postSeparatorFields
6057

6158
cg := &CgroupV1{
6259
MountPath: filepath.Dir(fields[4]),

cmd/runtimetest/mount/mountinfo_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func parseInfoFile(r io.Reader) ([]*Info, error) {
6464
}
6565
// Safe as mountinfo encodes mountpoints with spaces as \040.
6666
index := strings.Index(text, " - ")
67-
postSeparatorFields := strings.Fields(text[index+3:])
67+
postSeparatorFields := strings.Split(text[index+3:], " ")
6868
if len(postSeparatorFields) < 3 {
6969
return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text)
7070
}

0 commit comments

Comments
 (0)