From a8973c694a83229ef74e96e44a740dceabff1db3 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Tue, 7 Feb 2023 16:22:50 -0700 Subject: [PATCH] wrapper: fix segfault in cgroup_new_cgroup() Passing NULL in the place of the cgroup name as an argument to cgroup_new_cgroup() API will segfault, fix by adding a check to validate cgroup name. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- src/wrapper.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wrapper.c b/src/wrapper.c index a1a1efbf..0e724116 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -42,8 +42,12 @@ void init_cgroup_table(struct cgroup *cgroups, size_t count) struct cgroup *cgroup_new_cgroup(const char *name) { - struct cgroup *cgroup = calloc(1, sizeof(struct cgroup)); + struct cgroup *cgroup; + if (!name) + return NULL; + + cgroup = calloc(1, sizeof(struct cgroup)); if (!cgroup) return NULL; -- 2.47.2