Skip to content

Conversation

aschackmull
Copy link
Contributor

@aschackmull aschackmull commented Sep 17, 2024

Variable capture in constructors was only supported when the constructor was called directly - if the capture happened a call away, e.g. in the object initializer, which is a common pattern, then we failed to recognize it.

Fixes #17473

@@ -585,11 +585,13 @@ module Flow<LocationSig Location, InputSig<Location> Input> implements OutputSig
2 <= strictcount(CapturedVariable v | captureAccess(v, c))
or
// Constructors that capture a variable may assign it to a field, which also
// entails a this-to-this summary.
captureAccess(_, c) and c.isConstructor()
// entails a this-to-this summary. If there are multiple constructors, then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test case for the one-constructor-calls-another case you describe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add one.

@@ -248,4 +248,15 @@ void run() {
sink(l.get(0)); // $ hasValueFlow=src
sink(l2.get(0)); // $ hasValueFlow=src
}

void testInstanceInitializer() {
String s = source("init");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment noting that this is exercising specifically the obinit routine propagating taint?

@aschackmull aschackmull merged commit 2837d25 into github:main Sep 18, 2024
34 checks passed
@aschackmull aschackmull deleted the java/capture-in-obinit branch September 18, 2024 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DataFlow Library Java no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Taint propagation problem in AnonymousClass
2 participants