Skip to content

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Feb 15, 2021

This excludes its fluent methods for the time being, which will be added in an upcoming PR.

Based on #5126, review only latest commit.

Copy link
Contributor

@Marcono1234 Marcono1234 left a comment

Choose a reason for hiding this comment

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

StrBuilder is deprecated in the latest versions and has been moved to Apache Commons Text as TextStringBuilder. Would it make sense trying to cover that class as well?

/**
* A method declared on `org.apache.commons.lang3.text.StrBuilder`.
*/
abstract class ApacheStrBuilderMethod extends Callable {
Copy link
Contributor

@Marcono1234 Marcono1234 Feb 15, 2021

Choose a reason for hiding this comment

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

Suggested change
abstract class ApacheStrBuilderMethod extends Callable {
abstract class ApacheStrBuilderMethod extends Method {

Might be good to extend Method to be consistent with the class name.

Copy link
Contributor

Choose a reason for hiding this comment

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

When in doubt, don't use abstract classes. Indeed, I don't see any particular reason why we would want to use this feature here.

}

/**
* An Apache Commons-Lang StrBuilder methods that add taint to the StrBuilder.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* An Apache Commons-Lang StrBuilder methods that add taint to the StrBuilder.
* An Apache Commons Lang StrBuilder method that adds taint to the StrBuilder.

Here and for the other documentation comments: "Apache Commons Lang" should probably have no hyphen between "Commons" and "Lang".

}

/**
* An Apache Commons-Lang StrBuilder methods that return taint from the StrBuilder.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* An Apache Commons-Lang StrBuilder methods that return taint from the StrBuilder.
* An Apache Commons Lang StrBuilder method that returns taint from the StrBuilder.

}

/**
* An Apache Commons-Lang StrBuilder methods that write taint from the StrBuilder to some parameter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* An Apache Commons-Lang StrBuilder methods that write taint from the StrBuilder to some parameter.
* An Apache Commons Lang StrBuilder method that writes taint from the StrBuilder to some parameter.

@smowton smowton force-pushed the smowton/feature/commons-strbuilder branch from 6a1ad0b to 27cf907 Compare February 16, 2021 15:00
@smowton
Copy link
Contributor Author

smowton commented Feb 16, 2021

@aschackmull @Marcono1234 changes applied

@smowton
Copy link
Contributor Author

smowton commented Feb 16, 2021

Also added support for the commons-text version and for TextStringBuilder, a renamed version that also lives in common-text.

@@ -0,0 +1,2 @@
lgtm,codescanning
* Added support for the Apache Commons Lang StringUtils library.
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good mentioning the classes covered by this pull request, but probably after #5126 has been merged. Otherwise this will cause a merge conflict.

@smowton smowton force-pushed the smowton/feature/commons-strbuilder branch from 89b6dde to c700d00 Compare February 17, 2021 09:52
}

/**
* An Apache Commons Lang StrBuilder method that adds taint to the StrBuilder.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* An Apache Commons Lang StrBuilder method that adds taint to the StrBuilder.
* An Apache Commons Lang `StrBuilder` method that adds taint to the `StrBuilder`.

}

/**
* An Apache Commons Lang StrBuilder method that returns taint from the StrBuilder.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* An Apache Commons Lang StrBuilder method that returns taint from the StrBuilder.
* An Apache Commons Lang `StrBuilder` method that returns taint from the `StrBuilder`.

}

/**
* An Apache Commons Lang StrBuilder method that writes taint from the StrBuilder to some parameter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* An Apache Commons Lang StrBuilder method that writes taint from the StrBuilder to some parameter.
* An Apache Commons Lang `StrBuilder` method that writes taint from the `StrBuilder` to some parameter.


override predicate transfersTaint(int fromArg, int toArg) {
fromArg = -1 and
(
Copy link
Contributor

Choose a reason for hiding this comment

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

This parenthesis is superfluous.


StrBuilder sb1 = new StrBuilder(); sb1.append(taint().toCharArray()); sink(sb1.toString()); // $hasTaintFlow=y
StrBuilder sb2 = new StrBuilder(); sb2.append(taint().toCharArray(), 0, 0); sink(sb2.toString()); // $hasTaintFlow=y
StrBuilder sb3 = new StrBuilder(); sb3.append(CharBuffer.wrap(taint().toCharArray())); sink(sb3.toString()); // BAD (but not detected because we don't model CharBuffer yet)
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the inline test expectations library allow you to specify this as specifically being a false negative (it's not much different from this, but does lead to a suitable "Fixed" message in the .actual output in case this is handled in the future instead of complaining about an unexpected result).

@smowton
Copy link
Contributor Author

smowton commented Feb 18, 2021

@aschackmull done

@aschackmull aschackmull merged commit b1bed27 into github:main Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants