Skip to content

Commit 58d73eb

Browse files
samples/test_functions: terminate stack buffers
Add explicit '\0' writes after the strncpy() calls that populate the local group and target buffers so subsequent new_cgroup() and strncat() calls always see bounded, terminated strings. Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com> Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
1 parent 7ec2582 commit 58d73eb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

samples/c/test_functions.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ struct cgroup *create_new_cgroup_ds(int ctl, const char *grpname,
135135
int retval;
136136

137137
strncpy(group, grpname, sizeof(group) - 1);
138+
group[sizeof(group) - 1] = '\0';
139+
138140
retval = set_controller(ctl, controller_name, control_file);
139141
if (retval) {
140142
fprintf(stderr, "Setting controller failed\n");
@@ -691,7 +693,8 @@ build_path(char *target, char *mountpoint, const char *group, const char *file)
691693
if (!target)
692694
return;
693695

694-
strncpy(target, mountpoint, FILENAME_MAX);
696+
strncpy(target, mountpoint, FILENAME_MAX - 1);
697+
target[FILENAME_MAX - 1] = '\0';
695698

696699
if (group) {
697700
strncat(target, "/", FILENAME_MAX - strlen(target));

0 commit comments

Comments
 (0)