mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Add Expr::getUnderlyingExpr predicate
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: feature
|
||||
---
|
||||
* The QL predicate `Expr::getUnderlyingExpr` has been added. It can be used to look through casts and not-null expressions and obtain the underlying expression to which they apply.
|
||||
@@ -100,6 +100,18 @@ class Expr extends ExprParent, @expr {
|
||||
|
||||
/** Holds if this expression is parenthesized. */
|
||||
predicate isParenthesized() { isParenthesized(this, _) }
|
||||
|
||||
/**
|
||||
* Gets the underlying expression looking through casts and not-nulls, if any.
|
||||
* Otherwise just gets this expression.
|
||||
*/
|
||||
Expr getUnderlyingExpr() {
|
||||
if this instanceof CastingExpr or this instanceof NotNullExpr
|
||||
then
|
||||
result = this.(CastingExpr).getExpr().getUnderlyingExpr() or
|
||||
result = this.(NotNullExpr).getExpr().getUnderlyingExpr()
|
||||
else result = this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,7 @@ private predicate sharedPreferencesInput(DataFlow::Node editor, Expr input) {
|
||||
exists(MethodAccess m |
|
||||
m.getMethod() instanceof PutSharedPreferenceMethod and
|
||||
input = m.getArgument(1) and
|
||||
editor.asExpr() = m.getQualifier()
|
||||
editor.asExpr() = m.getQualifier().getUnderlyingExpr()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ private predicate sharedPreferencesInput(DataFlow::Node editor, Expr input) {
|
||||
*/
|
||||
private predicate sharedPreferencesStore(DataFlow::Node editor, MethodAccess m) {
|
||||
m.getMethod() instanceof StoreSharedPreferenceMethod and
|
||||
editor.asExpr() = m.getQualifier()
|
||||
editor.asExpr() = m.getQualifier().getUnderlyingExpr()
|
||||
}
|
||||
|
||||
/** Flow from `SharedPreferences.Editor` to either a setter or a store method. */
|
||||
|
||||
@@ -75,6 +75,8 @@ private predicate webViewLoadUrl(Argument urlArg, WebViewRef webview) {
|
||||
loadUrl.getArgument(0) = urlArg and
|
||||
loadUrl.getMethod() instanceof WebViewLoadUrlMethod
|
||||
|
|
||||
webview.getAnAccess() = DataFlow::exprNode(loadUrl.getQualifier().getUnderlyingExpr())
|
||||
or
|
||||
webview.getAnAccess() = DataFlow::getInstanceArgument(loadUrl)
|
||||
or
|
||||
// `webview` is received as a parameter of an event method in a custom `WebViewClient`,
|
||||
@@ -82,8 +84,9 @@ private predicate webViewLoadUrl(Argument urlArg, WebViewRef webview) {
|
||||
exists(WebViewClientEventMethod eventMethod, MethodAccess setWebClient |
|
||||
setWebClient.getMethod() instanceof WebViewSetWebViewClientMethod and
|
||||
setWebClient.getArgument(0).getType() = eventMethod.getDeclaringType() and
|
||||
loadUrl.getQualifier() = eventMethod.getWebViewParameter().getAnAccess()
|
||||
loadUrl.getQualifier().getUnderlyingExpr() = eventMethod.getWebViewParameter().getAnAccess()
|
||||
|
|
||||
webview.getAnAccess() = DataFlow::exprNode(setWebClient.getQualifier().getUnderlyingExpr()) or
|
||||
webview.getAnAccess() = DataFlow::getInstanceArgument(setWebClient)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user