Avoid memory leak if --args is specified multiple times#426
Draft
cgwalters wants to merge 1 commit intocontainers:mainfrom
Draft
Avoid memory leak if --args is specified multiple times#426cgwalters wants to merge 1 commit intocontainers:mainfrom
cgwalters wants to merge 1 commit intocontainers:mainfrom
Conversation
Found by a static analyzer.
```
bubblewrap-0.4.1/bubblewrap.c:1500: overwrite_var: Overwriting "opt_args_data" in "opt_args_data = load_file_data(the_fd, &data_len)" leaks the storage that "opt_args_data" points to.
# 1498| * keep allocated until exit time, since its argv entries get used
# 1499| * by the other cases in parse_args_recurse() when we recurse. */
# 1500|-> opt_args_data = load_file_data (the_fd, &data_len);
# 1501| if (opt_args_data == NULL)
# 1502| die_with_error ("Can't read --args data");
```
smcv
requested changes
Jun 10, 2021
| if (argv[1][0] == 0 || endptr[0] != 0 || the_fd < 0) | ||
| die ("Invalid fd: %s", argv[1]); | ||
|
|
||
| /* Specifying --args multiple times doesn't work; this just pacifies |
Collaborator
There was a problem hiding this comment.
The man page says it does, and that does seem to be true:
$ rmdir /tmp/a /tmp/b
$ printf '--dir\0/tmp/a\0' > a
$ printf '--dir\0/tmp/b\0' > b
$ bwrap --dev-bind / / --args 3 --args 4 ls /tmp 3<a 4<b
(output contains a and b)
So I think opt_args_data might need to become a linked list, or some other mechanism that keeps all of the arguments blobs referenced so that static analyzers know they are OK to "leak" once per process.
Collaborator
Author
There was a problem hiding this comment.
Eeek. This is why we have code review! It looks like at least flatpak (the main user of --args) is only appending it once, and for some reason I convinced myself the code was only designed to run once, but you're clearly right.
Collaborator
Author
There was a problem hiding this comment.
#428
and then will rework this to be a linked list or strv after that lands.
cgwalters
added a commit
to cgwalters/bubblewrap
that referenced
this pull request
Jun 10, 2021
The code supports this today, so test it. xref containers#426 where I thought it didn't.
cgwalters
added a commit
to cgwalters/bubblewrap
that referenced
this pull request
Jun 10, 2021
The code supports this today, so test it. xref containers#426 where I thought it didn't.
brandsimon
pushed a commit
to brandsimon/bubblewrap
that referenced
this pull request
Mar 19, 2023
The code supports this today, so test it. xref containers#426 where I thought it didn't.
CrackerCat
pushed a commit
to CrackerCat/bubblewrap
that referenced
this pull request
Jul 31, 2024
The code supports this today, so test it. xref containers#426 where I thought it didn't.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found by a static analyzer.