Skip to content

Commit

Permalink
fs: validate fd on fs.write
Browse files Browse the repository at this point in the history
PR-URL: #1553
PORT-PR-URL: #1560
PORT-FROM: v2.x / f9c681c
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
julianduque authored and Fishrock123 committed May 14, 2015
1 parent 898d423 commit 4030545
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,9 @@ static void Open(const FunctionCallbackInfo<Value>& args) {
static void WriteBuffer(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

CHECK(args[0]->IsInt32());
if (!args[0]->IsInt32())
return env->ThrowTypeError("First argument must be file descriptor");

CHECK(Buffer::HasInstance(args[1]));

int fd = args[0]->Int32Value();
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-fs-write-no-fd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const common = require('../common');
const fs = require('fs');
const assert = require('assert');

assert.throws(function() {
fs.write(null, new Buffer(1), 0, 1);
}, /TypeError/);

assert.throws(function() {
fs.write(null, '1', 0, 1);
}, /TypeError/);

0 comments on commit 4030545

Please sign in to comment.