]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
api.c: fix file open in cg_chmod_path()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 29 Aug 2022 21:03:56 +0000 (15:03 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 29 Aug 2022 21:04:56 +0000 (15:04 -0600)
commitd569122a8c5f9943e1842b5b776a8b1f84182f18
tree0cbf22e4e9bcc498f2dd60dd294f3c4bf502e99c
parent96db65fbb5296d4e66d1eb444c70d29b556e7eef
api.c: fix file open in cg_chmod_path()

In cg_chmod_path(), the commit 96db65fbb529 ("api.c: fix TOCTOU in
cg_chmod_path()), converted the file operations from stat -> fstat and
chmod -> fchmod to fix a Coverity warning.  The newly replaced file
operations operate on file descriptors and hence introduced a side
effect of opening the file at the wrong code block, that would only work
as expected when the caller calls cg_chmod_path() with owner_is_umask
set.

Fix it by moving the file operation out of the conditional block, so it
works in both of the cases of owner_is_umask being set or unset.

Fixes: 96db65fbb529 ("api.c: fix TOCTOU in cg_chmod_path())
Suggested-by: Tom Hromatka <tom.hromatka@oracle.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit 91cf2e4b7ceb19c02d66af717c18d7bc64fa5df9)
src/api.c