]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
wrapper: null terminated string in cgroup_add_controller()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Thu, 2 Jun 2022 16:01:18 +0000 (10:01 -0600)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 2 Jun 2022 16:01:22 +0000 (10:01 -0600)
Fix non-terminated string warning, reported by Coverity tool:

CID 258271 (#1 of 1): String not null terminated (STRING_NULL).
string_null: Passing unterminated string cgc->name to strcmp, which
expects a null-terminated string.

This issue was reported following the path src/abstraction-common.c:
- cgroup_convert_cgroup()
  - cgroup_add_controller()

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

index 98ebcc266c41f168b6865676d349499c7ff9e652..5ffdb0b4f54b23ecdb5f9d9befd569b38d2542ef 100644 (file)
@@ -83,6 +83,8 @@ struct cgroup_controller *cgroup_add_controller(struct cgroup *cgroup,
                return NULL;
 
        strncpy(controller->name, name, sizeof(controller->name) - 1);
+       controller->name[sizeof(controller->name) - 1] = '\0';
+
        controller->cgroup = cgroup;
        controller->index = 0;