]> git.ipfire.org Git - thirdparty/libcgroup.git/commit
wrapper: fix segfault in cgroup_get_uid_gid()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 28 Feb 2023 09:15:05 +0000 (14:45 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 28 Feb 2023 22:24:30 +0000 (15:24 -0700)
commit3d439e58f2487dca33ebf568ac323714a5c1ecfc
treeed9b82ef22e956d1d5608344d41b5b001f00430c
parentddcd79dede4265d891247004432f9c4e845a5a4a
wrapper: fix segfault in cgroup_get_uid_gid()

The arguments passed to cgroup_get_uid_gid() are of type pointers and
the user might pass NULL in place of or all of the arguments, causing
a segfault. segfault is triggered when the NULL, argument value is
passed without check, fix it by checking for NULL before proceeding.

Reproducer:
-----------

int main(void)
{
struct cgroup *cgrp;
uid_t tuid, cuid;
gid_t tgid, cgid;

int ret;

ret = cgroup_init();
if (ret) {
printf("Failed to initialize: %s\n", cgroup_strerror(ret));
exit (1);
}

cgrp = cgroup_new_cgroup("fuzzer");
if (!cgrp) {
printf("Failed to allocate cgroup fuzzer\n");
exit(1);
}

ret = cgroup_create_cgroup(cgrp, 1);
if (ret) {
printf("failed to create %s: %s\n", "fuzzer", cgroup_strerror(ret));
goto err;
}

cgroup_get_uid_gid(cgrp, NULL, NULL, NULL, NULL);
// should not reach here

return 0;
}

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