From: Kamalesh Babulal Date: Tue, 8 Feb 2022 16:44:50 +0000 (-0700) Subject: api.c: fix the buffer size to read /proc/cgroups X-Git-Tag: v3.0~207 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f813b5385b739236a4d6614f99160d664b871a2;p=thirdparty%2Flibcgroup.git api.c: fix the buffer size to read /proc/cgroups In cgroup_init(), the first line/header of /proc/cgroups helps in interpreting the values in the remaining of the file. We are interested in the rest of the file and a temporary buffer of size FILENAME_MAX is allocated/deallocated after reading the header. The length of the header is only 56 characters in length, excluding the newline. This patch reduces it to LL_MAX a.k.a 100 characters. LL_MAX is used instead of introducing another new length macro. Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index f47db98a..e9fbe420 100644 --- a/src/api.c +++ b/src/api.c @@ -1318,16 +1318,14 @@ int cgroup_init(void) /* * The first line of the file has stuff we are not interested in. * So just read it and discard the information. - * - * XX: fix the size for fgets */ - buf = malloc(FILENAME_MAX); + buf = malloc(LL_MAX); if (!buf) { last_errno = errno; ret = ECGOTHER; goto unlock_exit; } - if (!fgets(buf, FILENAME_MAX, proc_cgroup)) { + if (!fgets(buf, LL_MAX, proc_cgroup)) { free(buf); cgroup_err("Error: cannot read /proc/cgroups: %s\n", strerror(errno));