]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
lscgroup: Fix strncpy() truncation warning
authorTom Hromatka <tom.hromatka@oracle.com>
Tue, 27 Apr 2021 17:06:26 +0000 (17:06 +0000)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 27 Apr 2021 17:06:26 +0000 (17:06 +0000)
Fix the following strncpy() string truncation warning:

In function ‘strncpy’,
    inlined from ‘display_controller_data’ at lscgroup.c:99:2:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound 4096 equals destination size [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/tools/lscgroup.c

index bfb1724fa51a12482032674358045aac1aca5c0e..305b3428c76b1367cecf153e1dace532147858e2 100644 (file)
@@ -97,6 +97,7 @@ static int display_controller_data(char *input_path, char *controller, char *nam
                return ret;
 
        strncpy(cgroup_dir_path, info.full_path, FILENAME_MAX);
+       cgroup_dir_path[sizeof(cgroup_dir_path) - 1] = '\0';
        /* remove problematic  '/' characters from cgroup directory path*/
        trim_filepath(cgroup_dir_path);