]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
api: null terminate readlink buffer in cgroup_get_procname_from_procfs()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 27 Jul 2022 18:44:28 +0000 (12:44 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 27 Jul 2022 18:44:31 +0000 (12:44 -0600)
commit21c50cb860304ad99af920e80e48df941ecf7d75
tree4bb3ea7ffa6a28b508d3cce3a08c75ad04d5de6e
parentbfc9ee791899e57a25b5621205d154a7f91ffff7
api: null terminate readlink buffer in cgroup_get_procname_from_procfs()

Fix readlink buffer null termination warning, reported by Coverity tool:

CID 258273 (#2 of 2): String not null terminated (STRING_NULL).
string_null: Passing unterminated string buf to strdup, which expects a
null-terminated string.

As per the man pages (man 2 readlink):
"readlink() does not append a null byte to buf.  It  will (silently)
truncate the contents (to a length of bufsiz characters), in case the
buffer is too small to hold all of the contents."

Explicitly null terminate the buffer passed to readlink() in
cgroup_get_procname_from_procfs()

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