From: Kamalesh Babulal Date: Tue, 31 May 2022 22:54:28 +0000 (-0600) Subject: api: null terminated string in cgroup_get_controller_next() X-Git-Tag: v3.0~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d87e8453f6c0408aa92297952acb8e17f8ce08f2;p=thirdparty%2Flibcgroup.git api: null terminated string in cgroup_get_controller_next() 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 Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index 469e2426..d0e73410 100644 --- a/src/api.c +++ b/src/api.c @@ -5215,8 +5215,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;