]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: fix the buffer size to read /proc/cgroups
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 8 Feb 2022 16:44:50 +0000 (09:44 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 8 Feb 2022 16:44:55 +0000 (09:44 -0700)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index f47db98aa9788b3cc5614a4dcc8914f5f6bfc773..e9fbe420ae3c3801ca382348ee77a07da82f7092 100644 (file)
--- 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));