Commit
4a851a569689 ("api: Fix unsafe call to strncat in
cgroup_get_procs() and cgroup_get_threads()") tightened several
strncat() callers, but the code building the procs/threads paths
still used the raw remaining buffer size. When the buffer is
already full, strncat() would copy path_sz bytes and overwrite
the terminator. Subtract one from the remaining length before
appending "tasks" or the controller-specific filename so there
is always space for the trailing NUL.
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
switch (version) {
case CGROUP_V1:
- strncat(path, "tasks", path_sz - strlen(path));
+ strncat(path, "tasks", path_sz - strlen(path) - 1);
err = 0;
break;
case CGROUP_V2:
if (err)
goto error;
- strncat(path, cg_type, path_sz - strlen(path));
+ strncat(path, cg_type, path_sz - strlen(path) - 1);
break;
default:
err = ECGOTHER;