Skip to content

bwrap: Second attempt at fixing an argv handling leak#237

Closed
pwithnall wants to merge 2 commits intocontainers:masterfrom
pwithnall:224-leak
Closed

bwrap: Second attempt at fixing an argv handling leak#237
pwithnall wants to merge 2 commits intocontainers:masterfrom
pwithnall:224-leak

Conversation

@pwithnall
Copy link
Contributor

The first attempt caused a use-after-free because the arguments parsed
from --args are passed to parse_args_recurse(), and the other cases
there may take those pointers (without copying) into SetupOp structures,
which persist after data is freed.

Fix that by treating data more like the argv to main(): an allocation
which exists throughout the life of the program. Do that by hoisting its
declaration out as a global, and then pulling the allocated data into a
cleanup_free variable in main(), to tie its lifecycle to main().

The alternative is to strdup() each one of the argv elements when they
are used in parse_args_recurse(), but that would mean a lot more
allocations and frees, and a lot of code churn.

Signed-off-by: Philip Withnall withnall@endlessm.com

#224

A new test was added in commit c09c1e5, but the total number of tests
wasn’t incremented. Fix that.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
The first attempt caused a use-after-free because the arguments parsed
from --args are passed to parse_args_recurse(), and the other cases
there may take those pointers (without copying) into SetupOp structures,
which persist after data is freed.

Fix that by treating data more like the argv to main(): an allocation
which exists throughout the life of the program. Do that by hoisting its
declaration out as a global, and then pulling the allocated data into a
cleanup_free variable in main(), to tie its lifecycle to main().

The alternative is to strdup() each one of the argv elements when they
are used in parse_args_recurse(), but that would mean a lot more
allocations and frees, and a lot of code churn.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

containers#224
@smcv
Copy link
Collaborator

smcv commented Oct 10, 2017

Looks good. I'd r+ this if the bot trusted me.

@cgwalters
Copy link
Collaborator

@rh-atomic-bot delegate=smcv

@rh-atomic-bot
Copy link

✌️ @smcv can now approve this pull request

@cgwalters
Copy link
Collaborator

@smcv I sent you an invite as a collaborator.

@pwithnall
Copy link
Contributor Author

@smcv I sent you an invite as a collaborator.

bubblewrap party! 🎈 🎊 🎆 🎁

@smcv
Copy link
Collaborator

smcv commented Oct 10, 2017

@rh-atomic-bot r+ e7d09d3

@rh-atomic-bot
Copy link

⌛ Testing commit e7d09d3 with merge 96fee6f...

rh-atomic-bot pushed a commit that referenced this pull request Oct 10, 2017
A new test was added in commit c09c1e5, but the total number of tests
wasn’t incremented. Fix that.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #237
Approved by: smcv
rh-atomic-bot pushed a commit that referenced this pull request Oct 10, 2017
The first attempt caused a use-after-free because the arguments parsed
from --args are passed to parse_args_recurse(), and the other cases
there may take those pointers (without copying) into SetupOp structures,
which persist after data is freed.

Fix that by treating data more like the argv to main(): an allocation
which exists throughout the life of the program. Do that by hoisting its
declaration out as a global, and then pulling the allocated data into a
cleanup_free variable in main(), to tie its lifecycle to main().

The alternative is to strdup() each one of the argv elements when they
are used in parse_args_recurse(), but that would mean a lot more
allocations and frees, and a lot of code churn.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

#224

Closes: #237
Approved by: smcv
rh-atomic-bot pushed a commit that referenced this pull request Oct 10, 2017
The first attempt caused a use-after-free because the arguments parsed
from --args are passed to parse_args_recurse(), and the other cases
there may take those pointers (without copying) into SetupOp structures,
which persist after data is freed.

Fix that by treating data more like the argv to main(): an allocation
which exists throughout the life of the program. Do that by hoisting its
declaration out as a global, and then pulling the allocated data into a
cleanup_free variable in main(), to tie its lifecycle to main().

The alternative is to strdup() each one of the argv elements when they
are used in parse_args_recurse(), but that would mean a lot more
allocations and frees, and a lot of code churn.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

#224

Closes: #237
Approved by: smcv
@rh-atomic-bot
Copy link

☀️ Test successful - status-papr
Approved by: smcv
Pushing 96fee6f to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants