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

In function ‘strncpy’,
    inlined from ‘cgroup_parse_rules_file’ at api.c:798:3:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning: ‘__builtin___strncpy_chk’ output may be truncated copying between 0 and 255 bytes from a string of length 255 [-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

index 77c6838b4d7480dbadb897f7e120b7cc95356321..4e6e3b9e95451a7ce6fde02e95aed18dd26fa0e4 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -796,6 +796,8 @@ static int cgroup_parse_rules_file(char *filename, bool cache, uid_t muid,
                len_username = min(len_username,
                                        sizeof(newrule->username) - 1);
                strncpy(newrule->username, user, len_username);
+               newrule->username[sizeof(newrule->username) - 1] = '\0';
+
                if (len_procname) {
                        newrule->procname = strdup(procname);
                        if (!newrule->procname) {