-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ruby: Make array inclusion barrier more sensitive #11534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bb20ac9
to
99c06ad
Compare
@@ -116,7 +116,7 @@ private predicate stringConstArrayInclusionCall( | |||
isArrayConstant(t.getContainerNode().asExpr(), arr) | |||
| | |||
forall(ExprCfgNode elem | elem = arr.getAnArgument() | | |||
elem instanceof ExprNodes::StringLiteralCfgNode | |||
elem.getConstantValue().isStringlikeValue(_) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider replacing all occurrences of ExprNodes::StringLiteralCfgNode
in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to make sense, I think it would allow us to cover guards like:
guardvar = "safe"
case input
when guardvar
# input is validated
else
# input is not validated
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment, otherwise LGTM
This demonstrates that we are missing a guard when a case branch compares against a string-valued variable rather than a string literal.
This increases the sensitivity of our barrier guards.
448131e
to
4d228bc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DCA looks fine to me 👍
// Only consider strings without any interpolations | ||
not strLitNode.getExpr().getComponent(_) instanceof StringInterpolationComponent and | ||
exists(ExprCfgNode strNode | | ||
strNode.getConstantValue().isStringlikeValue(_) and | ||
c.getExpr() instanceof EqExpr and | ||
branch = true | ||
or | ||
c.getExpr() instanceof CaseEqExpr and branch = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strnode is not restricted in this disjunct and the one below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I missed this comment until recently. A fix for this is here: #12052
This change means we recognise barriers where a variable is tested for inclusion in an array which contains variables, rather than just string literals. The only requirement is that the variables have a stringlike
ConstantValue
.