prometheus / procfs

procfs provides functions to retrieve system, kernel and process metrics from the pseudo-filesystem proc.
Apache License 2.0
769 stars 319 forks source link

stat fails on process names with spaces #485

Closed gnewton closed 1 year ago

gnewton commented 1 year ago

Reference: https://www.openwall.com/lists/oss-security/2022/12/21/6

Failing test: in fixtures.tarr, change line 628 from 26231 (vim) R 5392 7446 5392 34835 7446 4218880 32533 309516 26 82 1677 44 158 99 20 0 1 0 82375 56274944 1981 18446744073709551615 4194304 6294284 140736914091744 140736914087944 139965136429984 0 0 12288 1870679807 0 0 0 17 0 0 0 31 0 0 8391624 8481048 16420864 140736914093252 140736914093279 140736914093279 140736914096107 0

to:

26231 (RDD Process) R 5392 7446 5392 34835 7446 4218880 32533 309516 26 82 1677 44 158 99 20 0 1 0 82375 56274944 1981 18446744073709551615 4194304 6294284 140736914091744 140736914087944 139965136429984 0 0 12288 1870679807 0 0 0 17 0 0 0 31 0 0 8391624 8481048 16420864 140736914093252 140736914093279 140736914093279 140736914096107 0

Before change:

$ make test
>> extracting fixtures testdata/fixtures
./ttar -C testdata/ -x -f testdata/fixtures.ttar
touch testdata/fixtures/.unpacked
>> running all tests
go test -race  ./...
ok      github.com/prometheus/procfs    0.220s
ok      github.com/prometheus/procfs/bcache 0.031s
ok      github.com/prometheus/procfs/blockdevice    0.028s
ok      github.com/prometheus/procfs/btrfs  0.027s
ok      github.com/prometheus/procfs/internal/fs    (cached)
ok      github.com/prometheus/procfs/internal/util  (cached)
ok      github.com/prometheus/procfs/iscsi  0.023s
ok      github.com/prometheus/procfs/nfs    (cached)
ok      github.com/prometheus/procfs/sysfs  0.081s
ok      github.com/prometheus/procfs/xfs    0.029s

After above change:

$ make test
>> extracting fixtures testdata/fixtures
./ttar -C testdata/ -x -f testdata/fixtures.ttar
touch testdata/fixtures/.unpacked
>> running all tests
go test -race  ./...
--- FAIL: TestProcStatComm (0.00s)
    proc_stat_test.go:113: want comm vim, have RDD Process
FAIL
FAIL    github.com/prometheus/procfs    0.209s
ok      github.com/prometheus/procfs/bcache 0.025s
ok      github.com/prometheus/procfs/blockdevice    0.031s
ok      github.com/prometheus/procfs/btrfs  0.029s
ok      github.com/prometheus/procfs/internal/fs    (cached)
ok      github.com/prometheus/procfs/internal/util  (cached)
ok      github.com/prometheus/procfs/iscsi  0.023s
ok      github.com/prometheus/procfs/nfs    (cached)
ok      github.com/prometheus/procfs/sysfs  0.081s
ok      github.com/prometheus/procfs/xfs    0.028s
FAIL
make: *** [Makefile.common:151: common-test] Error 1

Commit and env:

$ git rev-parse HEAD
bb7727a9ca9b3cd1559b42ffa74e13ef7efb6283
$ uname -a
Linux optiplex7010 5.15.0-56-generic #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
$ go version
go version go1.18 linux/amd64
gnewton commented 1 year ago

Apologies, the above changes to fixtures.ttar do not show the issue, just me not properly understanding these tests.

gnewton commented 1 year ago

Just wrote a short Go program that indicates parsing spaces is ok.