Skip to content

Commit

Permalink
apparmor: fix incorrect usage of sizeof on char ptr
Browse files Browse the repository at this point in the history
In criu/apparmor.c: write_aa_policy(), the arg path is passed as a char
pointer. The original code used sizeof(path) to get the size of it,
which is incorrect as it always return the size of the char pointer
(typically 8 or 4), not the actual capacity of the char array.

Given that this function is only invoked with path declared as `char
path[PATH_MAX]`, replacing sizeof(path) with PATH_MAX should correctly
represent the maximum size of it.

Fixes: 8723e3f ("check: add a feature test for apparmor_stacking")

Signed-off-by: Haorong Lu <[email protected]>
  • Loading branch information
ancientmodern committed Aug 2, 2023
1 parent 88249fe commit 1c7af5e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions criu/apparmor.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,8 @@ static int write_aa_policy(AaNamespace *ns, char *path, int offset, char *rewrit
goto fail;
}

ret = snprintf(path + offset + my_offset, sizeof(path) - offset - my_offset, "/.replace");
if (ret < 0 || ret >= sizeof(path) - offset - my_offset) {
ret = snprintf(path + offset + my_offset, PATH_MAX - offset - my_offset, "/.replace");
if (ret < 0 || ret >= PATH_MAX - offset - my_offset) {
pr_err("snprintf failed\n");
goto fail;
}
Expand Down

0 comments on commit 1c7af5e

Please sign in to comment.