Skip to content

Commit e027e7e

Browse files
committed
fix(memlimit): fix mountinfo validation logic for multiple optional fields
1 parent 00da85b commit e027e7e

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
@@ -269,11 +269,9 @@ func parseMountInfoLine(line string) (mountInfo, error) {
269269
return mountInfo{}, fmt.Errorf("invalid separator")
270270
}
271271

272-
fields1 := strings.Split(fieldss[0], " ")
272+
fields1 := strings.SplitN(fieldss[0], " ", 7)
273273
if len(fields1) < 6 {
274274
return mountInfo{}, fmt.Errorf("not enough fields before separator: %v", fields1)
275-
} else if len(fields1) > 7 {
276-
return mountInfo{}, fmt.Errorf("too many fields before separator: %v", fields1)
277275
} else if len(fields1) == 6 {
278276
fields1 = append(fields1, "")
279277
}

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 left side",
62-
input: "36 35 98:0 /mnt1 /mnt2 rw,noatime extra master:1 - ext3 /dev/root rw,errors=continue",
63-
wantErr: `too many fields before separator: [36 35 98:0 /mnt1 /mnt2 rw,noatime extra master:1]`,
64-
},
6560
{
6661
name: "too many fields on right side",
6762
input: "36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw extra",
@@ -82,6 +77,16 @@ func TestParseMountInfoLine(t *testing.T) {
8277
SuperOptions: "rw,relatime",
8378
},
8479
},
80+
{
81+
name: "multiple optional fields on left side (issue #26)",
82+
input: "465 34 253:0 / / rw,relatime shared:409 master:1 - xfs /dev/mapper/fedora-root rw,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota",
83+
want: mountInfo{
84+
Root: "/",
85+
MountPoint: "/",
86+
FilesystemType: "xfs",
87+
SuperOptions: "rw,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota",
88+
},
89+
},
8590
}
8691

8792
for _, tt := range tests {

0 commit comments

Comments
 (0)