Skip to content

Commit a659ed1

Browse files
committed
fix(memlimit): fix mountinfo validation logic when super options have spaces
1 parent b5e3683 commit a659ed1

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

memlimit/cgroups.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,9 @@ func parseMountInfoLine(line string) (mountInfo, error) {
276276
fields1 = append(fields1, "")
277277
}
278278

279-
fields2 := strings.Split(fieldss[1], " ")
279+
fields2 := strings.SplitN(fieldss[1], " ", 3)
280280
if len(fields2) < 3 {
281281
return mountInfo{}, fmt.Errorf("not enough fields after separator: %v", fields2)
282-
} else if len(fields2) > 3 {
283-
return mountInfo{}, fmt.Errorf("too many fields after separator: %v", fields2)
284282
}
285283

286284
return mountInfo{

memlimit/cgroups_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ func TestParseMountInfoLine(t *testing.T) {
5757
input: "36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3",
5858
wantErr: `not enough fields after separator: [ext3]`,
5959
},
60-
{
61-
name: "too many fields on right side",
62-
input: "36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw extra",
63-
wantErr: `too many fields after separator: [ext3 /dev/root rw extra]`,
64-
},
6560
{
6661
name: "empty line",
6762
input: "",
@@ -87,6 +82,16 @@ func TestParseMountInfoLine(t *testing.T) {
8782
SuperOptions: "rw,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota",
8883
},
8984
},
85+
{
86+
name: "super options have spaces (issue #28)",
87+
input: `1391 1160 0:151 / /Docker/host rw,noatime - 9p C:\134Program\040Files\134Docker\134Docker\134resources rw,dirsync,aname=drvfs;path=C:\Program Files\Docker\Docker\resources;symlinkroot=/mnt/,mmap,access=client,msize=65536,trans=fd,rfd=3,wfd=3`,
88+
want: mountInfo{
89+
Root: "/",
90+
MountPoint: "/Docker/host",
91+
FilesystemType: "9p",
92+
SuperOptions: `rw,dirsync,aname=drvfs;path=C:\Program Files\Docker\Docker\resources;symlinkroot=/mnt/,mmap,access=client,msize=65536,trans=fd,rfd=3,wfd=3`,
93+
},
94+
},
9095
}
9196

9297
for _, tt := range tests {

0 commit comments

Comments
 (0)