]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tools/cgsnapshot: fix string null terminate in parse_controllers()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 19 Jul 2023 07:05:50 +0000 (12:35 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 19 Jul 2023 17:42:50 +0000 (11:42 -0600)
Fix string not null terminated warning, reported by the Coverity tool:

CID 258299 (#2 of 2): String not null terminated (STRING_NULL)18.
string_null: Passing unterminated string *controllers to
display_controller_data, which expects a null-terminated string.

use snprintf() instead of strncpy() and manually terminate the string to
keep Coverity happy.

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

index 9917e134db43aed2469a3bb6ae47a2eb4570ff4f..ff5cc108f2cfe32942c92b8b2aa05245309dc94b 100644 (file)
@@ -529,8 +529,7 @@ static int is_ctlr_on_list(char controllers[CG_CONTROLLER_MAX][FILENAME_MAX],
 
        /* Lets reset the controllers to intersection of controller ∩ wanted_conts */
        for (i = 0; tmp_controllers[i][0] != '\0'; i++) {
-               strncpy(controllers[i], tmp_controllers[i], FILENAME_MAX - 1);
-               (controllers[i])[FILENAME_MAX - 1] = '\0';
+               snprintf(controllers[i], FILENAME_MAX, "%s", tmp_controllers[i]);
                ret = 1;
        }
        (controllers[i])[0] = '\0';