]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: fix strncpy() warning in cgroup_process_v2_mnt
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Mon, 28 Feb 2022 14:07:20 +0000 (19:37 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 4 Mar 2022 16:07:08 +0000 (09:07 -0700)
Fix a GCC warning about un-truncated strncpy() in
cgroup_process_v2_mnt():

In function 'cgroup_process_v2_mnt',
    inlined from 'cgroup_init' at api.c:1387:10:
api.c:1205:9: warning: 'strncpy' specified bound 4096 equals destination size [-Wstringop-truncation]
 1205 |         strncpy(cg_cgroup_v2_mount_path, ent->mnt_dir, FILENAME_MAX);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

index 488cdd5f09a2d32155dbf7bcbb3c041dc35f50de..69dce7fcadd5d76f740525e2d3e954b8e959bdbf 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1202,7 +1202,8 @@ STATIC int cgroup_process_v2_mnt(struct mntent *ent, int *mnt_tbl_idx)
         * Save off this mount point.  This may be used later to build
         * the cg_path.
         */
-       strncpy(cg_cgroup_v2_mount_path, ent->mnt_dir, FILENAME_MAX);
+       strncpy(cg_cgroup_v2_mount_path, ent->mnt_dir, FILENAME_MAX-1);
+       cg_cgroup_v2_mount_path[FILENAME_MAX-1] = '\0';
 
        /* determine what v2 controllers are available on this mount */
        snprintf(cgroup_controllers_path, FILENAME_MAX, "%s/%s", ent->mnt_dir,
diff --git a/tests b/tests
index 3e786fc4c024662cc38c8a39868354c55465f487..2aa90061eccb7dbd3d3ce7f6cdf2e087cf8a95a2 160000 (submodule)
--- a/tests
+++ b/tests
@@ -1 +1 @@
-Subproject commit 3e786fc4c024662cc38c8a39868354c55465f487
+Subproject commit 2aa90061eccb7dbd3d3ce7f6cdf2e087cf8a95a2