I ran a cppcheck scan on the repository and found 2 instances of state->arch = &pseudo_arch that are not reset before 6 return paths:
<errorid="autoVariables"severity="error"msg="Address of local auto-variable assigned to a function parameter."verbose="Dangerous assignment - the function parameter is assigned the address of a local auto-variable. Local auto-variables are reserved from the stack which is freed when the function ends. So the pointer to a local variable is invalid after the function ends."cwe="562">
<locationfile="/workspace/src/gen_bpf.c"line="2029"column="2"/>
</error>
<errorid="autoVariables"severity="error"msg="Address of local auto-variable assigned to a function parameter."verbose="Dangerous assignment - the function parameter is assigned the address of a local auto-variable. Local auto-variables are reserved from the stack which is freed when the function ends. So the pointer to a local variable is invalid after the function ends."cwe="562">
<locationfile="/workspace/src/gen_bpf.c"line="2102"column="2"/>
</error>
state->arch has a longer lifetime than pseudo_arch and the function _gen_bpf_build_bpf returns without resetting state->arch.
Fix
Set state->arch = NULL before the return statements
Why?
Although there are no use-after-free instances that I could find, future code modifications may not be verifying that, so it makes sense to keep the code clean and avoid future problems.
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
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.
Problem
I ran a cppcheck scan on the repository and found 2 instances of state->arch = &pseudo_arch that are not reset before 6 return paths:
state->arch has a longer lifetime than pseudo_arch and the function _gen_bpf_build_bpf returns without resetting state->arch.
Fix
Why?
Verification