]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: null terminated string in cgroup_get_controller_next()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 31 May 2022 22:55:47 +0000 (16:55 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 31 May 2022 22:55:51 +0000 (16:55 -0600)
Fix non-terminated string warnings, reported by Coverity tool:

CID 258299 (#1-2 of 2): String not null terminated (STRING_NULL).
string_null: Passing unterminated string controller.path to strcmp,
which expects a null-terminated string

This issue was reported following the path src/tools/cgsnapshot.c:
- parse_controllers()
  - cgroup_get_controller_begin()
    - cgroup_get_controller_next()

Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 5b94521557f4981d4d53fe6f71f7933bb044e3fe..7f67657feff918a87d12981dc25705f42be16825 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -4958,8 +4958,10 @@ int cgroup_get_controller_next(void **handle, struct cgroup_mount_point *info)
        }
 
        strncpy(info->name, cg_mount_table[*pos].name, FILENAME_MAX - 1);
+       info->name[FILENAME_MAX - 1] = '\0';
 
        strncpy(info->path, cg_mount_table[*pos].mount.path, FILENAME_MAX - 1);
+       info->path[FILENAME_MAX - 1] = '\0';
 
        (*pos)++;
        *handle = pos;