Fix two snprintf string truncation warnings in
cg_build_path_locked().
api.c:1475:38: warning: ‘snprintf’ output may be truncated before the
last format character [-Wformat-truncation=]
1475 | snprintf(path, FILENAME_MAX, "%s/",
| ^
api.c:1475:5: note: ‘snprintf’ output between 2 and 4097 bytes into a
destination of size 4096
1475 | snprintf(path, FILENAME_MAX, "%s/",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1476 | cg_mount_table[i].mount.path);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
api.c:1470:40: warning: ‘/’ directive output may be truncated writing 1
byte into a region of size between 0 and 4095 [-Wformat-truncation=]
1470 | snprintf(path, FILENAME_MAX, "%s/%s/",
| ^
api.c:1470:5: note: ‘snprintf’ output 3 or more bytes (assuming 4098)
into a destination of size 4096
1470 | snprintf(path, FILENAME_MAX, "%s/%s/",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1471 | cg_mount_table[i].mount.path,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1472 | cg_namespace_table[i]);
| ~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Tom Hromatka <[email protected]>
---
src/api.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/api.c b/src/api.c
index a6f4e46b673a..68357e673a11 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1463,18 +1463,27 @@ static char *cg_concat_path(const char *pref, const
char *suf, char *path)
char *cg_build_path_locked(const char *name, char *path,
const char *type)
{
- int i;
+ int i, ret;
for (i = 0; cg_mount_table[i].name[0] != '\0'; i++) {
if (strcmp(cg_mount_table[i].name, type) == 0) {
if (cg_namespace_table[i]) {
- snprintf(path, FILENAME_MAX, "%s/%s/",
+ ret = snprintf(path, FILENAME_MAX, "%s/%s/",
cg_mount_table[i].mount.path,
cg_namespace_table[i]);
path[FILENAME_MAX-1] = '\0';
+ if (ret >= FILENAME_MAX)
+ cgroup_dbg("Warning: filename too long:"
+ "%s/%s/",
+ cg_mount_table[i].mount.path,
+ cg_namespace_table[i]);
} else {
- snprintf(path, FILENAME_MAX, "%s/",
+ ret = snprintf(path, FILENAME_MAX, "%s/",
cg_mount_table[i].mount.path);
path[FILENAME_MAX-1] = '\0';
+ if (ret >= FILENAME_MAX)
+ cgroup_dbg("Warning: filename too long:"
+ "%s/",
+ cg_mount_table[i].mount.path);
}
if (name) {
--
2.26.2
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel