From ea1e44b035b1ce0c6fae92081c856f58bfc05ba5 Mon Sep 17 00:00:00 2001 From: Stephan Brandauer Date: Wed, 27 Apr 2022 14:03:22 +0200 Subject: [PATCH] use ? for unknown parameternames --- .../EndpointFeatures.qll | 9 +++++- .../FeatureValue.expected | 30 +++++++++---------- .../test/generic_feature_testing/test.js | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/EndpointFeatures.qll b/javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/EndpointFeatures.qll index 942169f3e30..c2add821db4 100644 --- a/javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/EndpointFeatures.qll +++ b/javascript/ql/experimental/adaptivethreatmodeling/lib/experimental/adaptivethreatmodeling/EndpointFeatures.qll @@ -563,7 +563,7 @@ private module SyntacticUtilities { result = "(" + concat(string parameter, int i | - parameter = f.getParameter(i).getName() + parameter = getParameterNameOrUnknown(f.getParameter(i)) | parameter, ", " order by i ) + ")" @@ -727,6 +727,13 @@ private module SyntacticUtilities { then result = ref.getPropertyName() else result = getUnknownSymbol() } + + /** + * Gets the parameter name if it exists, or `?` if it is unknown. + */ + string getParameterNameOrUnknown(Parameter p) { + if exists(p.getName()) then result = p.getName() else result = getUnknownSymbol() + } } /** diff --git a/javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/FeatureValue.expected b/javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/FeatureValue.expected index 80cd24aa252..bde7231ec6b 100644 --- a/javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/FeatureValue.expected +++ b/javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/FeatureValue.expected @@ -15,7 +15,7 @@ | test.js:6:7:6:14 | endpoint | calleeApiName | lib3 | | test.js:6:7:6:14 | endpoint | calleeImports | ? lib3 | | test.js:6:7:6:14 | endpoint | calleeName | f | -| test.js:6:7:6:14 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:6:7:6:14 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:6:7:6:14 | endpoint | contextSurroundingFunctionParameters | () | | test.js:6:7:6:14 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:6:7:6:14 | endpoint | enclosingFunctionName | | @@ -26,7 +26,7 @@ | test.js:7:11:7:18 | endpoint | calleeAccessPath | | | test.js:7:11:7:18 | endpoint | calleeAccessPathWithStructuralInfo | | | test.js:7:11:7:18 | endpoint | calleeImports | ? lib3 | -| test.js:7:11:7:18 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:7:11:7:18 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:7:11:7:18 | endpoint | contextSurroundingFunctionParameters | () | | test.js:7:11:7:18 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:7:11:7:18 | endpoint | enclosingFunctionName | | @@ -37,7 +37,7 @@ | test.js:8:15:8:22 | endpoint | calleeAccessPath | | | test.js:8:15:8:22 | endpoint | calleeAccessPathWithStructuralInfo | | | test.js:8:15:8:22 | endpoint | calleeImports | ? lib3 | -| test.js:8:15:8:22 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:8:15:8:22 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:8:15:8:22 | endpoint | contextSurroundingFunctionParameters | () | | test.js:8:15:8:22 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:8:15:8:22 | endpoint | enclosingFunctionName | | @@ -50,7 +50,7 @@ | test.js:9:9:9:16 | endpoint | calleeApiName | lib2 | | test.js:9:9:9:16 | endpoint | calleeImports | ? lib2 | | test.js:9:9:9:16 | endpoint | calleeName | m | -| test.js:9:9:9:16 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:9:9:9:16 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:9:9:9:16 | endpoint | contextSurroundingFunctionParameters | () | | test.js:9:9:9:16 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:9:9:9:16 | endpoint | enclosingFunctionName | | @@ -62,7 +62,7 @@ | test.js:10:13:10:20 | endpoint | calleeAccessPath | | | test.js:10:13:10:20 | endpoint | calleeAccessPathWithStructuralInfo | | | test.js:10:13:10:20 | endpoint | calleeImports | ? lib2 | -| test.js:10:13:10:20 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:10:13:10:20 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:10:13:10:20 | endpoint | contextSurroundingFunctionParameters | () | | test.js:10:13:10:20 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:10:13:10:20 | endpoint | enclosingFunctionName | | @@ -73,7 +73,7 @@ | test.js:11:17:11:24 | endpoint | calleeAccessPath | | | test.js:11:17:11:24 | endpoint | calleeAccessPathWithStructuralInfo | | | test.js:11:17:11:24 | endpoint | calleeImports | ? lib2 | -| test.js:11:17:11:24 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:11:17:11:24 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:11:17:11:24 | endpoint | contextSurroundingFunctionParameters | () | | test.js:11:17:11:24 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:11:17:11:24 | endpoint | enclosingFunctionName | | @@ -83,7 +83,7 @@ | test.js:12:11:12:18 | endpoint | calleeAccessPath | | | test.js:12:11:12:18 | endpoint | calleeAccessPathWithStructuralInfo | | | test.js:12:11:12:18 | endpoint | calleeImports | lib1 | -| test.js:12:11:12:18 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:12:11:12:18 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:12:11:12:18 | endpoint | contextSurroundingFunctionParameters | () | | test.js:12:11:12:18 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:12:11:12:18 | endpoint | enclosingFunctionName | | @@ -96,7 +96,7 @@ | test.js:13:17:13:24 | endpoint | calleeApiName | lib2 | | test.js:13:17:13:24 | endpoint | calleeImports | ? lib2 | | test.js:13:17:13:24 | endpoint | calleeName | m | -| test.js:13:17:13:24 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:13:17:13:24 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:13:17:13:24 | endpoint | contextSurroundingFunctionParameters | () | | test.js:13:17:13:24 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:13:17:13:24 | endpoint | enclosingFunctionName | | @@ -108,7 +108,7 @@ | test.js:14:9:14:16 | endpoint | calleeAccessPathWithStructuralInfo | lib3 instanceorreturn instanceorreturn | | test.js:14:9:14:16 | endpoint | calleeApiName | lib3 | | test.js:14:9:14:16 | endpoint | calleeImports | ? lib3 | -| test.js:14:9:14:16 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:14:9:14:16 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:14:9:14:16 | endpoint | contextSurroundingFunctionParameters | () | | test.js:14:9:14:16 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:14:9:14:16 | endpoint | enclosingFunctionName | | @@ -121,7 +121,7 @@ | test.js:15:12:15:19 | endpoint | calleeApiName | lib2 | | test.js:15:12:15:19 | endpoint | calleeImports | ? lib2 | | test.js:15:12:15:19 | endpoint | calleeName | m | -| test.js:15:12:15:19 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:15:12:15:19 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:15:12:15:19 | endpoint | contextSurroundingFunctionParameters | () | | test.js:15:12:15:19 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:15:12:15:19 | endpoint | enclosingFunctionName | | @@ -134,7 +134,7 @@ | test.js:16:16:16:23 | endpoint | calleeApiName | lib2 | | test.js:16:16:16:23 | endpoint | calleeImports | ? lib2 | | test.js:16:16:16:23 | endpoint | calleeName | m | -| test.js:16:16:16:23 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:16:16:16:23 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:16:16:16:23 | endpoint | contextSurroundingFunctionParameters | () | | test.js:16:16:16:23 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:16:16:16:23 | endpoint | enclosingFunctionName | | @@ -146,7 +146,7 @@ | test.js:17:15:17:22 | endpoint | calleeAccessPathWithStructuralInfo | lib1 member p instanceorreturn | | test.js:17:15:17:22 | endpoint | calleeApiName | lib1 | | test.js:17:15:17:22 | endpoint | calleeImports | lib1 | -| test.js:17:15:17:22 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:17:15:17:22 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:17:15:17:22 | endpoint | contextSurroundingFunctionParameters | () | | test.js:17:15:17:22 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:17:15:17:22 | endpoint | enclosingFunctionName | | @@ -159,7 +159,7 @@ | test.js:18:27:18:34 | endpoint | calleeApiName | foo | | test.js:18:27:18:34 | endpoint | calleeImports | foo | | test.js:18:27:18:34 | endpoint | calleeName | baz | -| test.js:18:27:18:34 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:18:27:18:34 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:18:27:18:34 | endpoint | contextSurroundingFunctionParameters | () | | test.js:18:27:18:34 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:18:27:18:34 | endpoint | enclosingFunctionName | | @@ -172,7 +172,7 @@ | test.js:20:13:20:20 | endpoint | calleeApiName | lib1 | | test.js:20:13:20:20 | endpoint | calleeImports | lib1 | | test.js:20:13:20:20 | endpoint | calleeName | bar | -| test.js:20:13:20:20 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:20:13:20:20 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:20:13:20:20 | endpoint | contextSurroundingFunctionParameters | () | | test.js:20:13:20:20 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:20:13:20:20 | endpoint | enclosingFunctionName | | @@ -183,7 +183,7 @@ | test.js:22:21:22:28 | endpoint | calleeAccessPathWithStructuralInfo | lib3 instanceorreturn | | test.js:22:21:22:28 | endpoint | calleeApiName | lib3 | | test.js:22:21:22:28 | endpoint | calleeImports | ? lib2 lib3 | -| test.js:22:21:22:28 | endpoint | contextFunctionInterfacesInFile | f(endpoint)\nfoo()\ng()\nm() | +| test.js:22:21:22:28 | endpoint | contextFunctionInterfacesInFile | f(?)\nfoo()\ng()\nm() | | test.js:22:21:22:28 | endpoint | contextSurroundingFunctionParameters | () | | test.js:22:21:22:28 | endpoint | enclosingFunctionBody | f endpoint f p endpoint f p q endpoint o m endpoint o m p endpoint o m p q endpoint F endpoint o m m m endpoint f endpoint o x m endpoint o m x p m endpoint p endpoint foo bar baz endpoint foo bar endpoint f f o m endpoint | | test.js:22:21:22:28 | endpoint | enclosingFunctionName | | diff --git a/javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/test.js b/javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/test.js index 92bb10d58f9..da7c016ceaa 100644 --- a/javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/test.js +++ b/javascript/ql/experimental/adaptivethreatmodeling/test/generic_feature_testing/test.js @@ -22,7 +22,7 @@ const f = require('lib3'); (f() ? f : o.m)(endpoint); }); -function f(endpoint) {} +function f({ endpoint }) {} const g = async () => undefined;