Skip to content

Commit

Permalink
adaptived: ftests: Fix freeing of invalid pointer in test 1003
Browse files Browse the repository at this point in the history
Fix the following error in sudo test 1003:

	<snip>
	Debug: handle_special_properties: property=CPUQuota,
	value->value.str_value=44%, real property: CPUQuotaPerSecUSec
	Debug: handle_special_properties: sd_bus_message_append(m, (sv),
	CPUQuotaPerSecUSec, t, 440000
	Debug: adaptived main loop exceeded max loops
	free(): invalid pointer
	Aborted

Test 1003 was re-using the "len" variable and this was confusing
getline().  getline() was then re-using a buffer even though it wasn't
large enough, leading to a memory corruption.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
  • Loading branch information
drakenclimber authored and gkennedy12 committed Dec 13, 2024
1 parent 2fefd58 commit 621dd33
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions adaptived/tests/ftests/1003-sudo-effect-sd_bus_setting-CPUQuota.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ static const int expected_period = 1000000;

int main(int argc, char *argv[])
{
char *cgrp_path = NULL, *cgrp_file = NULL;
char *cgrp_path = NULL;
char config_path[FILENAME_MAX];
char expected_buf[FILENAME_MAX];
char cgrp_file[FILENAME_MAX];
struct adaptived_ctx *ctx = NULL;
int ret, version, read_value;
FILE * fp;
Expand Down Expand Up @@ -88,10 +89,8 @@ int main(int argc, char *argv[])
goto err;

len = strlen(cgrp_path) + 1 + strlen("cpu.cfs_period_us") + 1;
cgrp_file = malloc(sizeof(char) * len);

memset(cgrp_file, 0, sizeof(char) * len);

memset(cgrp_file, 0, sizeof(cgrp_file));
sprintf(cgrp_file, "%s/cpu.cfs_period_us", cgrp_path);

fp = fopen(cgrp_file, "r");
Expand All @@ -110,8 +109,7 @@ int main(int argc, char *argv[])
if (read_value != expected_period)
goto err;

memset(cgrp_file, 0, sizeof(char) * len);

memset(cgrp_file, 0, sizeof(cgrp_file));
sprintf(cgrp_file, "%s/cpu.cfs_quota_us", cgrp_path);

fp = fopen(cgrp_file, "r");
Expand All @@ -137,10 +135,8 @@ int main(int argc, char *argv[])
sprintf(expected_buf, "%d %d\n", expected_quota, expected_period);

len = strlen(cgrp_path) + 1 + strlen("cpu.max") + 1;
cgrp_file = malloc(sizeof(char) * len);

memset(cgrp_file, 0, sizeof(char) * len);

memset(cgrp_file, 0, sizeof(cgrp_file));
sprintf(cgrp_file, "%s/cpu.max", cgrp_path);

fp = fopen(cgrp_file, "r");
Expand All @@ -162,8 +158,6 @@ int main(int argc, char *argv[])
free(line);
adaptived_release(&ctx);
stop_transient(cgroup_slice_name);
if (cgrp_file)
free(cgrp_file);
if (cgrp_path)
free(cgrp_path);

Expand All @@ -174,8 +168,6 @@ int main(int argc, char *argv[])
free(line);
adaptived_release(&ctx);
stop_transient(cgroup_slice_name);
if (cgrp_file)
free(cgrp_file);
if (cgrp_path)
free(cgrp_path);

Expand Down

0 comments on commit 621dd33

Please sign in to comment.