Fix the following warnings from clang by reducing the size passed to
strncat by 1 as recommended by clang.
api.c:3727:22: warning: the value of the size argument in 'strncat' is
too large, might lead to a buffer overflow [-Wstrncat-size]
3727 | strncat(path, file, sizeof(path) - strlen(path));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
api.c:3727:22: note: change the argument to be the free space in the
destination buffer minus the terminating null byte
3727 | strncat(path, file, sizeof(path) - strlen(path));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
| sizeof(path) - strlen(path) - 1
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
if (!cg_build_path_locked(cgrp, path, subsys))
return ECGFAIL;
- strncat(path, file, sizeof(path) - strlen(path));
+ strncat(path, file, sizeof(path) - strlen(path) - 1);
ctrl_file = fopen(path, "re");
if (!ctrl_file)
return ECGROUPVALUENOTEXIST;