Skip to content

Commit 4c9a6b7

Browse files
authored
Merge pull request github#3107 from erik-krogh/FArgs
Approved by esbena
2 parents a1e032b + 833183c commit 4c9a6b7

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

change-notes/1.24/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
| Use of password hash with insufficient computational effort (`js/insufficient-password-hash`) | Fewer false positive results | This query now recognizes additional cases that do not require secure hashing. |
8383
| Useless regular-expression character escape (`js/useless-regexp-character-escape`) | Fewer false positive results | This query now distinguishes escapes in strings and regular expression literals. |
8484
| Identical operands (`js/redundant-operation`) | Fewer results | This query now recognizes cases where the operands change a value using ++/-- expressions. |
85+
| Superfluous trailing arguments (`js/superfluous-trailing-arguments`) | Fewer results | This query now recognizes cases where a function uses the `Function.arguments` value to process a variable number of parameters. |
8586

8687
## Changes to libraries
8788

javascript/ql/src/semmle/javascript/Functions.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,14 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
117117
ArgumentsVariable getArgumentsVariable() { result.getFunction() = this }
118118

119119
/** Holds if the body of this function refers to the function's `arguments` variable. */
120-
predicate usesArgumentsObject() { exists(getArgumentsVariable().getAnAccess()) }
120+
predicate usesArgumentsObject() {
121+
exists(getArgumentsVariable().getAnAccess())
122+
or
123+
exists(PropAccess read |
124+
read.getBase() = getVariable().getAnAccess() and
125+
read.getPropertyName() = "arguments"
126+
)
127+
}
121128

122129
/**
123130
* Holds if this function declares a parameter or local variable named `arguments`.

javascript/ql/test/query-tests/LanguageFeatures/SpuriousArguments/tst.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,13 @@ parseFloat("123", 10);
120120
throwerWithParam(42, 87); // NOT OK
121121
throwerIndirect(42); // OK, but still flagged due to complexity
122122
});
123+
124+
function sum2() {
125+
var result = 0;
126+
for (var i=0,n=sum2.arguments.length; i<n; ++i)
127+
result += sum2.arguments[i];
128+
return result;
129+
}
130+
131+
// OK
132+
sum2(1, 2, 3);

0 commit comments

Comments
 (0)