-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathno-unsafe-alloc.js
44 lines (42 loc) · 1.48 KB
/
no-unsafe-alloc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
"use strict";
module.exports = {
meta: {
type: "suggestion",
fixable: "code",
schema: [],
docs: {
description:
"When calling [`Buffer.allocUnsafe`](https://nodejs.org/api/buffer.html#buffer_static_method_buffer_allocunsafe_size) and [`Buffer.allocUnsafeSlow`](https://nodejs.org/api/buffer.html#buffer_static_method_buffer_allocunsafeslow_size), the allocated memory is not wiped-out and can contain old, potentially sensitive data.",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-unsafe-alloc.md"
},
messages: {
default: "Do not allocate uninitialized buffers in Node.js"
}
},
create: function (context) {
return {
"MemberExpression[object.name='Buffer'][property.name=/allocUnsafe|allocUnsafeSlow/]"(node) {
// Known false positives
if (
node.parent != undefined &&
node.parent.arguments != undefined &&
node.parent.arguments.length != undefined &&
// Buffer.allocUnsafe(0);
node.parent.type === "CallExpression" &&
node.parent.arguments.length == 1 &&
node.parent.arguments[0] != undefined &&
node.parent.arguments[0].type === "Literal" &&
node.parent.arguments[0].value == "0"
) {
return;
}
context.report({
node: node,
messageId: "default"
});
}
};
}
};