]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
tools/cgget: fix segfault in get_cv_value()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 19 Sep 2022 13:56:09 +0000 (07:56 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 19 Sep 2022 13:56:12 +0000 (07:56 -0600)
commit10f973e09581ca5565c9a54d796094dfcca8fdac
treee600ea2e8563f969013c09b568f9047ace963966
parent0a535d4988183bb708f7df86c03476a288e16da0
tools/cgget: fix segfault in get_cv_value()

cgget segfaulted on v2.0.2 branch, with:
cgget: cannot find controller 'incal' in group '016cgget'
Fatal error: glibc detected an invalid stdio handle
Aborted (core dumped)

It was caught by ftests/016-cgget-invalid_options.py on Ubuntu 22.04, a
simple reproducer on the v2.0.2 branch:
$ sudo ./src/tools/cgget -n -v -r invalid.setting 016cgget
assuming 016cgget cgroup exists.

It is due to the invalid controller name passed to the
cgroup_read_value_begin(), which returns failure and callee
get_cv_value() in the error clean up path, does a fclose(handle).
If (handle != NULL) succeeds because its uninitialized and has some
garbage value. Fix this by initializing the handle to NULL.

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit c8af263a8802b48a3fdc0de68e6408d72619e172)
src/tools/cgget.c