]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
config.c: Silence Coverity warning about unterminated string
authorTom Hromatka <tom.hromatka@oracle.com>
Tue, 7 Jan 2020 15:03:49 +0000 (08:03 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 8 Jan 2020 15:01:39 +0000 (08:01 -0700)
This commit silences the following Coverity warning:

CID 1412118 (#1 of 1): Buffer not null terminated
(BUFFER_SIZE_WARNING)6. buffer_size_warning: Calling strncpy with a
maximum size argument of 4096 bytes on destination array mount->name of
size 4096 bytes might leave the destination string unterminated.

Note that there are several areas (including this piece of code)
in libcgroup that do not gracefully handle string truncation.  That
will be addressed in future patches.

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

index 48d73cae900515e18b901efa2d778cbd7ce776e2..3ffa263714055536f850385e39c3fdd11d71478e 100644 (file)
@@ -652,6 +652,7 @@ static int cgroup_config_ajdust_mount_options(struct cg_mount_table_s *mount,
                                if (controller == NULL)
                                        break;
                                strncpy(mount->name, controller, sizeof(mount->name));
+                               mount->name[sizeof(mount->name)-1] = '\0';
                        }
 
                        if (strncmp(token, "nodev", strlen("nodev")) == 0) {