Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebf9ba7

Browse files
committed
remove the type-overloaded new Buffer() as a sink
1 parent e2b7f7d commit ebf9ba7

2 files changed

Lines changed: 24 additions & 24 deletions

File tree

javascript/ql/lib/semmle/javascript/security/dataflow/ResourceExhaustionCustomizations.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ module ResourceExhaustion {
9797
or
9898
invk = clazz.getAnInvocation() and
9999
(
100-
invk.getNumArgument() = 1 and // `new Buffer(size)`, it's only an issue if the size is a number, which we don't track precisely.
101-
index = 0
102-
or
100+
// invk.getNumArgument() = 1 and // `new Buffer(size)`, it's only an issue if the size is a number, which we don't track precisely.
101+
// index = 0
102+
// or
103103
invk.getNumArgument() = 3 and index = 2 // the length argument
104104
)
105105
)

javascript/ql/test/query-tests/Security/CWE-770/ResourceExhaustion/resource-exhaustion.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var server = http.createServer(function(req, res) {
1515
Buffer.allocUnsafe(n); // NOT OK
1616
Buffer.allocUnsafeSlow(n); // NOT OK
1717

18-
new Buffer(n); // NOT OK
18+
new Buffer(n); // NOT OK - but not flagged [INCONSISTENCY]
1919
new Buffer(x, n); // OK
2020
new Buffer(x, y, n); // NOT OK
2121

@@ -34,48 +34,48 @@ var server = http.createServer(function(req, res) {
3434
x.repeat(n); // NOT OK
3535
x.repeat(s); // NOT OK
3636

37-
new Buffer(n * x); // NOT OK
38-
new Buffer(n + n); // NOT OK
39-
new Buffer(n + x); // OK (maybe) - but still flagged [INCONSISTENCY]
40-
new Buffer(n + s); // OK (this is a string if `s` is a string) - but still flagged [INCONSISTENCY]
41-
new Buffer(s + 2); // OK (this is a string if `s` is a string) - but still flagged [INCONSISTENCY]
42-
new Buffer(s + s); // OK - but still flagged [INCONSISTENCY]
43-
new Buffer(n + "X"); // OK - but still flagged [INCONSISTENCY]
37+
new Buffer(n * x); // NOT OK - but not flagged [INCONSISTENCY]
38+
new Buffer(n + n); // NOT OK - but not flagged [INCONSISTENCY]
39+
new Buffer(n + x); // OK (maybe)
40+
new Buffer(n + s); // OK (this is a string if `s` is a string)
41+
new Buffer(s + 2); // OK (this is a string if `s` is a string)
42+
new Buffer(s + s); // OK
43+
new Buffer(n + "X"); // OK
4444

45-
new Buffer(Math.ceil(s)); // NOT OK
46-
new Buffer(Number(s)); // NOT OK
45+
new Buffer(Math.ceil(s)); // NOT OK - but not flagged [INCONSISTENCY]
46+
new Buffer(Number(s)); // NOT OK - but not flagged [INCONSISTENCY]
4747
new Buffer(new Number(s)); // OK
4848

49-
new Buffer(s + x.length); // OK (this is a string if `s` is a string) - but still flagged [INCONSISTENCY]
50-
new Buffer(s.length); // NOT OK
49+
new Buffer(s + x.length); // OK (this is a string if `s` is a string)
50+
new Buffer(s.length); // NOT OK - but not flagged [INCONSISTENCY]
5151

5252
if (n < 100) {
5353
new Buffer(n); // OK
5454
} else {
55-
new Buffer(n); // NOT OK
55+
new Buffer(n); // NOT OK - but not flagged [INCONSISTENCY]
5656
}
5757

5858
let ns = x ? n : s;
59-
new Buffer(ns); // NOT OK
59+
new Buffer(ns); // NOT OK - but not flagged [INCONSISTENCY]
6060

61-
new Buffer(n.toString()); // OK - but still flagged [INCONSISTENCY]
61+
new Buffer(n.toString()); // OK
6262

6363
if (typeof n === "string") {
64-
new Buffer(n); // OK - but still flagged [INCONSISTENCY]
64+
new Buffer(n); // OK
6565
} else {
66-
new Buffer(n); // NOT OK
66+
new Buffer(n); // NOT OK - but not flagged [INCONSISTENCY]
6767
}
6868

6969
if (typeof n === "number") {
70-
new Buffer(n); // NOT OK
70+
new Buffer(n); // NOT OK - but not flagged [INCONSISTENCY]
7171
} else {
72-
new Buffer(n); // OK - but still flagged [INCONSISTENCY]
72+
new Buffer(n); // OK
7373
}
7474

7575
if (typeof s === "number") {
76-
new Buffer(s); // NOT OK
76+
new Buffer(s); // NOT OK - but not flagged [INCONSISTENCY]
7777
} else {
78-
new Buffer(s); // OK - but stil flagged [INCONSISTENCY]
78+
new Buffer(s); // OK
7979
}
8080

8181
setTimeout(f, n); // NOT OK

0 commit comments

Comments
 (0)