Skip to content

Commit f9c681c

Browse files
committed
fs: validate fd on fs.write
PR-URL: #1553 Reviewed-By: Colin Ihrig <[email protected]>
1 parent 509b59e commit f9c681c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/node_file.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,9 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
779779
static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
780780
Environment* env = Environment::GetCurrent(args);
781781

782-
CHECK(args[0]->IsInt32());
782+
if (!args[0]->IsInt32())
783+
return env->ThrowTypeError("First argument must be file descriptor");
784+
783785
CHECK(Buffer::HasInstance(args[1]));
784786

785787
int fd = args[0]->Int32Value();

test/parallel/test-fs-write-no-fd.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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/);

0 commit comments

Comments
 (0)