Skip to content

Commit 7ec2582

Browse files
samples/read_stats: terminate cgrp_path buffers
This adds an explicit '\0' after each strncpy() in the sample so the subsequent strcat calls stay within bounds. Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
1 parent d436b6a commit 7ec2582

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

samples/c/read_stats.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,15 @@ int main(int argc, char *argv[])
5555
}
5656

5757
ret = cgroup_walk_tree_begin(controller, "/", 0, &handle, &info, &lvl);
58-
5958
if (ret != 0) {
6059
fprintf(stderr, "Walk failed\n");
6160
exit(EXIT_FAILURE);
6261
}
6362

6463
root_len = strlen(info.full_path) - 1;
6564
strncpy(cgrp_path, info.path, FILENAME_MAX - 1);
65+
cgrp_path[FILENAME_MAX - 1] = '\0';
66+
6667
ret = read_stats(cgrp_path, controller);
6768
if (ret < 0)
6869
exit(EXIT_FAILURE);
@@ -71,8 +72,11 @@ int main(int argc, char *argv[])
7172
ECGEOF) {
7273
if (info.type != CGROUP_FILE_TYPE_DIR)
7374
continue;
75+
7476
strncpy(cgrp_path, info.full_path + root_len, FILENAME_MAX - 1);
77+
cgrp_path[FILENAME_MAX - 1] = '\0';
7578
strcat(cgrp_path, "/");
79+
7680
ret = read_stats(cgrp_path, controller);
7781
if (ret < 0)
7882
exit(EXIT_FAILURE);

0 commit comments

Comments
 (0)