GeezerVison is showing github.com — fs: validate fd on fs.write · Fishrock123/node@f9c681c
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_file.cc +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -779,7 +779,9 @@ static void Open(const FunctionCallbackInfo<Value>& args) { |
779 | 779 | static void WriteBuffer(const FunctionCallbackInfo<Value>& args) { |
780 | 780 | Environment* env = Environment::GetCurrent(args); |
781 | 781 |
|
782 | | - CHECK(args[0]->IsInt32()); |
| 782 | + if (!args[0]->IsInt32()) |
| 783 | + return env->ThrowTypeError("First argument must be file descriptor"); |
| 784 | + |
783 | 785 | CHECK(Buffer::HasInstance(args[1])); |
784 | 786 |
|
785 | 787 | int fd = args[0]->Int32Value(); |
|
Collapse file
Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +const common = require('../common'); |
| 2 | +const fs = require('fs'); |
| 3 | +const assert = require('assert'); |
| 4 | + |
| 5 | +assert.throws(function() { |
| 6 | + fs.write(null, new Buffer(1), 0, 1); |
| 7 | +}, /TypeError/); |
| 8 | + |
| 9 | +assert.throws(function() { |
| 10 | + fs.write(null, '1', 0, 1); |
| 11 | +}, /TypeError/); |